Skip to main content

Can we Return ResultSet ??? from a web service....When i write im getting

4 replies [Last post]
vivekroy143
Offline
Joined: 2009-04-13
Points: 0

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package Ravi;
import java.sql.*;
import java.sql.ResultSet;
import javax.jws.WebMethod;
import javax.jws.WebService;

/**
*
* @author dinesh
*/
@WebService()
public class ServerSide {

/**
* Web service operation
*/
@WebMethod(operationName = "Billa")
public ResultSet Billa() {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "";
String dbName = "";
String driver = "";
String db_userName = "";
String db_password = "";
ResultSet rs;
try {
System.out.println("Database Name "+db_userName);
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,db_userName,db_password);
System.out.println("Connected to the database");
Statement statement = conn.createStatement();
rs = statement.executeQuery("SELECT * FROM content");
while (rs.next()) {
System.out.println("Loop ");
}
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

Error:--
javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262)
at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:218)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:119)
at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:61)
at com.sun.tools.ws.spi.WSToolsObjectFactory.wsgen(WSToolsObjectFactory.java:107)
at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1845)
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2249)
at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:424)
at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:157)
at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:179)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
java.sql.ResultSet does not have a no-arg default constructor.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:148)
... 18 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
java.sql.ResultSet does not have a no-arg default constructor.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:438)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:286)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)
... 20 more
Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment Error -- Exception occured in the wsgen process javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1848)
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2249)
at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:424)
at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:157)
at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:179)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262)
at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:218)
at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:119)
at com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsgen(WSToolsObjectFactoryImpl.java:61)
at com.sun.tools.ws.spi.WSToolsObjectFactory.wsgen(WSToolsObjectFactory.java:107)
at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1845)
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2249)
at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:424)
at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:157)
at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:179)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
java.sql.ResultSet does not have a no-arg default constructor.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:148)
... 18 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
java.sql.ResultSet does not have a no-arg default constructor.
this problem is related to the following location:
at java.sql.ResultSet
at private java.sql.ResultSet Ravi.jaxws.BillaResponse._return
at Ravi.jaxws.BillaResponse
at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:438)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:286)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)
... 20 more
Exception occured in J2EEC Phase
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment Error -- Exception occured in the wsgen process javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.enterprise.webservice.WsUtil.runWsGen(WsUtil.java:1848)
at com.sun.enterprise.webservice.WsUtil.genWSInfo(WsUtil.java:2249)
at com.sun.enterprise.deployment.backend.ModuleDeployer.loadDescriptors(ModuleDeployer.java:424)
at com.sun.enterprise.deployment.backend.WebModuleDeployer.deploy(WebModuleDeployer.java:157)
at com.sun.enterprise.deployment.backend.ModuleDeployer.doRequestFinish(ModuleDeployer.java:179)
at com.sun.enterprise.deployment.phasing.J2EECPhase.runPhase(J2EECPhase.java:191)
at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:279)
at com.sun.enterprise.deployment.phasing.PEDeploymentService.deploy(PEDeploymentService.java:788)
at com.sun.enterprise.management.deploy.DeployThread.deploy(DeployThread.java:187)
at com.sun.enterprise.management.deploy.DeployThread.run(DeployThread.java:223)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
deanc76
Offline
Joined: 2010-02-24
Points: 0

You are correct, you can't respond with an interface.

What you can do instead is reply a double array Object.

i.e:
Object[][] myWebSerice(int numColumns){

Statement st = con.getStatement();
ResultSet rs = st.execuiteQuery('some SQl statement);

//First measure how many rows are avaliable
rs.last();
int numRows = rs.getRow();
rs.beforeFirst();

//You now have the row and colum count, initiate the object array
Object returnArray[][] = new Object[numRows][numColumns];

//Now just populate the array, first array for rows, second array for coloumns
for(int row=0; row rs.next();
for(int col=0; col //Populate the Object Array
returnArray[row][col] = rs.getObject[col];
}
}

return returnArray

}

On the client side you will need to know what each object is suposed to be.
i.e: A String, boolean, int etc...

Problem here is you can't cast from Object to a promitve. No big issue though, just use the Class equavelent
i.e:

String responseString = (String)returnArray[x][y]; is OK as not Primitave but
int responseInt = (int)returnArray[x][y]; fails as it is a primitave
Just use the Class Integer
int responseInt = (Integer)returnArray[x][y];
or
boolean b = (Boolean)returnArray[x][y];
etc.

Another aproach that I just thought of but havnt tested is you could pass the WebService an array of classes:
i.e: Class c[] = new Class(java.lang.String, java.lang.String, boolean, int etc..)
Make the Class array a quasi Schema for what the database should return and use it as the rs.get.....
i.e:
if(c[0] instanceof String)String s = rs.GetString(i);
else if(c[0] instanceof int)int i = rs.etInt(i);

Need some more thought on this one but it has some promise.

}

lalit_lmc
Offline
Joined: 2009-03-23
Points: 0

Generally the good idea is that first define your message structure and than map them back into your class, which is also knows as WSDL first approach. you cna generate JAXB classes from your XML message structure and than fill those objects from your REsultSet. This will keep a level of indirection in your code.

ipsi
Offline
Joined: 2009-02-04
Points: 0

Not going to happen. If you have a look through the error listing, it explicitly says that "ResultSet is an Interface and JAXB can't handle interfaces".

You'll need to transform the ResultSet into a set of Classes that JAXB *can* handle. As far as I understand it, this will require that you have the properties you need fixed in the class - I don't imagine JAXB can handle dynamic properties either.

Thus, if your table has the columns ColOne, ColTwo, ColThree, you'll need a class with the following three to six methods (the setters could possibly be omitted):

getColOne();
getColTwo();
getColThree();
setColOne();
setColTwo();
setColThree();

As I understand it, this is all occurring before your code is actually executed - it's inspecting your class and attempting construct an XSD schema from the properties it exposes. Unfortunately, since the important properties of a ResultSet can't be known until the code actually executes, returning a ResultSet does no good at all.

I hope that helps.

velujeya
Offline
Joined: 2007-06-21
Points: 0

Dear Friends,
I am very new to this web service world. I have developed few test web services and now I am trying to develop an actual web service for a client. Basically I am trying to write a web service that can serve the data from a database. I tried "return resultSet", but it wasn't working. I understand that "ipsi" mentioned that I have to create an object which can map the ResultSet. But if I have more than one record then should I save those different objects in a ArrayList and then return a ArrayList or what would be the best way to solve this issue.

Please give me some suggestions...

Thanks,
velujeya