Hello!
I have a tricky problem that I cannot solve on my own. I want to use JDBC
from within my web service implementation to query an Access 2000 database
via ODBC (System DSN) and return the answer. That is, the java method
implementing the web service uses JDBC. For some reason this doesn't work.
The program containing the method runs just fine when executed directly from
the command prompt, but when it is invoked by calling the web service from
an Axis client I get a createSQLException with a trace back to
Method.invoke() among others (see below). I have tried many things and it
seems to me that my database cannot be queried from within the Axis-process
that is executing the web service. Why is that?
Have anybody else encountered a similar problem, and how did you solve it?
Please help!
PS. How can I open a text file from within a web service and use it? The
default path/user.dir property is c:\winnt\system32 from the perspective of
the running web service so the text file is never found. I have tried to set
the user.dir property to directory ..\axis\WEB-INF\classes without success.
DS.
Here is the code implementing my web service:
public synchronized String getCarsByOwner(String ownerSSN) {
String sqlResult;
try {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbURL = "jdbc:odbc:carsdatabase";
// Load driver and connect to database
Class.forName(driver).newInstance();
Connection connection =
DriverManager.getConnection(dbURL);
PreparedStatement stmnt =
connection.prepareStatement("SELECT * "+
"FROM Cars "+
"WHERE Owner=3D"+ownerSSN);
ResultSet res = stmnt.executeQuery();
sqlResult = convertQueryResultToString();
} catch(Exception e) {
StackTraceElement[] ste = e.getStackTrace();
StringBuffer buf = new StringBuffer();
for(int i=0; i<ste.length; i++) {
buf.append(ste[i].toString());
buf.append(endl);
}
sqlResult = buf.toString();
}
return sqlResult;
}
And here is the error received:
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6987)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
java.sql.DriverManager.getConnection(DriverManager.java:512)
java.sql.DriverManager.getConnection(DriverManager.java:193)
datasources.cars.CarsDBClient$1.run(CarsDBClient.java:117)
datasources.cars.CarsDBClient.getCarsByOwner(CarsDBClient.java:138)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java
:39
)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
mpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397
)
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.jav
a:304)
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:329)
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:
71)
org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:157)
org.apache.axis.SimpleChain.invoke(SimpleChain.java:122)
org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:517)
org.apache.axis.server.AxisServer.invoke(AxisServer.java:324)
org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:639)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:
339)
........
Best regards
Martin