JDBC Access to SQL Server Database in IBM WebSphere 5.1
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Achyuth_Belgundi
Posted On:   Tuesday, February 10, 2004 07:44 AM

Hello, I have written a simple java bean for database(SQL Server) connection and deployed in IBM Websphere Server. One of our jsp page is gonna access this java bean for user authentication. I am using the jre (v1.4.1) available in IBM WebSphere 5.1. When below code executes, the exception is thrown saying "No Suitable Driver". The driver used is sun.jdbc.odbc.JdbcOdbcDriver. I have enabled the trace for Jdbc part and the trace details is given below (after the code sample). From one of the sites, i have got information that "No Suitable Driver" exception to JdbcOdbcDriver if the libraries is not found/available. I have checked in WebSphereAppserverjava for JdbcOdbc.dll and found that it is missing. Will it be ok i   More>>


Hello,

I have written a simple java bean for database(SQL Server) connection and deployed in IBM Websphere Server. One of our jsp page is gonna access this java bean for user authentication.

I am using the jre (v1.4.1) available in IBM WebSphere 5.1. When below code executes, the exception is thrown saying "No Suitable Driver". The driver used is sun.jdbc.odbc.JdbcOdbcDriver. I have enabled the trace for Jdbc part and the trace details is given below (after the code sample). From one of the sites, i have got information that "No Suitable Driver" exception to JdbcOdbcDriver if the libraries is not found/available. I have checked in WebSphereAppserverjava for JdbcOdbc.dll and found that it is missing. Will it be ok if i copy the JdbcOdbc.dll file alone?


Kindly suggest me why the solution for this problem. Thanks in advance.



Also It would be great, if you can provide me, any sample code with other jdbc drivers connecting to SQL Server that can be deployed in IBM WebSphere 5.1



Thank you very much in advance.




Code Sample:


private Connection getConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

DriverManager.setLogWriter(writer);

con = DriverManager.getConnection("jdbc:odbc:tata-aig","sa","");

System.out.println("Connection line executed."+con);

}

catch(SQLException sqlExc){

System.out.println("SQL MESSAGE:"+sqlExc.getMessage());

sqlExc.printStackTrace();

}

catch(ClassNotFoundException classNFoundExc) {

System.out.println("CLASS MESSAGE:"+classNFoundExc.getMessage());

classNFoundExc.printStackTrace();

}

return con;

}

public boolean login(String user, String pwd) {

boolean validFlag = false;

try {

System.out.println("USER:"+user);

System.out.println("PASSWORD:"+pwd);

con = getConnection();

System.out.println("Connection Established..."+con);

selectStmt = con.createStatement();

result = selectStmt.executeQuery("select pwd from Login where userId = '" + user + "'");

System.out.println("Query Executed...");

if(result.next()){

System.out.println("Record Found");

String dbPwd = result.getString("pwd");

if(dbPwd.equals(pwd)) {

validFlag = true;

}

else {

validFlag = false;

}

}

}catch(SQLException sqlExc){

sqlExc.printStackTrace();

}

return validFlag;

}



Trace Details:


trying driver[className=com.ibm.db2j.jdbc.EmbeddedDriver30,com.ibm.db2j.jdbc.EmbeddedDriver30@2d7f4a59]

trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@2c5cca75]

*Driver.connect (jdbc:odbc:tata-aig)

JDBC to ODBC Bridge: Checking security

No SecurityManager present, assuming trusted
application/applet

JDBC to ODBC Bridge 2.0001

Current Date/Time: Tue Feb 10 06:11:15 IST 2004

Loading JdbcOdbc library

Unable to load JdbcOdbc library

java.sql.SQLException: Unable to load JdbcOdbc library

at sun.jdbc.odbc.JdbcOdbc. (JdbcOdbc.java:80)

at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:311)

at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:149)

at java.sql.DriverManager.getConnection(DriverManager.java:538)

at java.sql.DriverManager.getConnection(DriverManager.java:188)

at com.tataaig.LoginManager.getConnection(LoginManager.java:35)

at com.tataaig.LoginManager.login(LoginManager.java:53)

at org.apache.jsp._ValidateUser._jspService(_ValidateUser.java:120)

at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)

at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:662)

at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)

at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)

at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)

at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)

at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)

at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Unable to load JdbcOdbc library
Unable to allocate environment
getConnection: no suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:558)
at java.sql.DriverManager.getConnection(DriverManager.java:188)
at com.tataaig.LoginManager.getConnection(LoginManager.java:35)
at com.tataaig.LoginManager.login(LoginManager.java:53)
at org.apache.jsp._ValidateUser._jspService(_ValidateUser.java:120)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:662)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)


SQLException: SQLState(08001)

SQL MESSAGE:No suitable driver

   <<Less

Re: JDBC Access to SQL Server Database in IBM WebSphere 5.1

Posted By:   peter_Nordlander  
Posted On:   Wednesday, March 17, 2004 10:28 AM

The driver seems not to be included in the IBM jvm in WebSphere.
If you start your code as a java app with a main, the driver is found.
I am now in the process of finding a suitable jar with the driver to put in the lib folder
About | Sitemap | Contact