jdbc Tomcat db2
Hello Java Gurus,
Please please please help me with my problem. I have an application which connects to db2 through tomcat 4.0.1. But I am unable to connect to the database. The following are my errors:
java.lang.UnsatisfiedLinkError: SQLAllocEnv
at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method)
at COM.ibm.db2.jdbc.app.DB2Driver.(DB2Driver.java:244)
at COM.ibm.db2.jdbc.app.DB2Driver.(DB2Driver.java:129)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at database.Database.(Database.java:30)
at database.ConnectionPool.allocateConnection(ConnectionPool.java:117)
at database.ConnectionPool.getConnection(ConnectionPool.java:33)
at persistence.AbstractEntityFactory.makeEntityArray(AbstractEntityFactory.java:153)
at persistence.AbstractEntityFactory.makeInitializedEntityArray(AbstractEntityFactory.java:131)
at persistence.AbstractEntityFactory.select(AbstractEntityFactory.java:102)
at achp.persistence.generated.StaffEntityFactory.select(StaffEntityFactory.java:30)
at achp.persistence.generated.StaffEntity.select(StaffEntity.java:21)
at achp.presentation.UserBean.login(UserBean.java:143)
I know that its a jdbc problem.... I copied Db2java.jar file to all the lib directories in tomcat, but the problem still persists. I dont know what else I should do. Please help me resolve this.
Thanks a million.
Uma
[1483 byte] By [
ushasku] at [2007-9-30 22:28:41]

Is there anyone who can rescue meThanks
This seems to be a classloading problem. Did you try adding the JAR file (with the loaction) to the CLASSPATH.Annie.
Yes, I did add the location to my classpath and path....but the error still seem to persist.......any more suggestions.Thanks
you are using the app-driver of DB2.
It connects via DB-Connect to the DB2-Server.
DB-Connect is running natively. That means, that you must have installed it .
The app-driver accesses DB-connect via JNI. So there is a native library (a dll or a so). that must be on the computer, where the tomcat is running.
2 solutions:
1) not just copy the db2java.jar file to tomcats classpath or to your war. You must install a DB-Connect client on that computer.
2) use the net-driver (COM.ibm.db2.jdbc.net.DB2Driver) that also comes with db2java.jar. It is 100% Java. No JNI-stuff.
It is slightly slower than the app-driver.
The url is a bit different. As far as I remember it is
jdbc:db2://hostname:port//dbname
important : you have to run the command db2jstrt <portnumber> on the server. It means that the server respondes on that port to the net-drivers requests.
Another point:
Using db2 it is very important to have the vary same version of driver and server.
Perseios--Thanks for your reply.
I did as you said but I am getting new error now:
java.lang.RuntimeException: Problem getting DB connection: [IBM][JDBC Driver] CLI0615E Error receiving from socket, server is not responding. SQLSTATE=08S01
at database.Database.getConnection(Database.java:82)
at database.ConnectionPool.allocateConnection(ConnectionPool.java:117)
at database.ConnectionPool.getConnection(ConnectionPool.java:33)
at persistence.AbstractEntityFactory.makeEntityArray(AbstractEntityFactory.java:153)
at persistence.AbstractEntityFactory.makeInitializedEntityArray(AbstractEntityFactory.java:131)
at persistence.AbstractEntityFactory.select(AbstractEntityFactory.java:102)
at achp.persistence.generated.StaffEntityFactory.select(StaffEntityFactory.java:30)
at achp.persistence.generated.StaffEntity.select(StaffEntity.java:21)
at achp.presentation.UserBean.login(UserBean.java:143)
How should I proceed ? Please reply me back.
Thanks
hi
What exactly did you? I gave you two different solutions.
I suppose you misunderstood in some way. I will explain again.
There are two different ways of JDBC-connecting to DB2 offered by IBM:
1) access via the COM.ibm.db2.jdbc.app.DB2Driver
This access requires DB2 Client-software (DB-Connect) installed on the local machine (the computer where tomcat runs).
To use this access, you must call the Client-Configuration programm of DB2 and make a local name for the Database you want to access.
Now you can open it in JDBC with the url jdbc:db2:<local-databasename>
By the way: having given the name, you could also acces it via the jdbc-odbc bridge.
2) The alternative way is to connect via the COM.ibm.db2.jdbc.net.DB2Driver
This access is designed for easy-to-deploy clients tlike applets or stand-alone clients where an installation of the (native) DB2-client is too complicated. (In fact it is)
Access is slower compared to the app-driver.
To be able to use it, you must run the db2jstrt <portnumber> command on the DB-Server. (NOT on the computer, where the tomcat runs., but on the computer, where DB2 runs).
To run this command, there are two ways (you must do it physically on the db2-server):
-just open a DB2-console (you find it in the task-bar) and type the command
-if you don't find the DB2-console on the task bar: open a console and navigate to the IBM-installation/SQLLIB/bin directory and type the command
After that, you can JDBC connect with the net-driver via the url
jdbc:db2:/<DB2-server-IP>:<tport-number>/<database-name>
<port-number> is the number, you used with the db2jstrt command
clearly for a webserver, the natural choice would be the app-driver
hope this helps
Hi
The first error you got is because a native component cannot be located by your driver. The reason is that you use a type II driver : java code call via JNI a specific code associated to these driver. Solution : install client software.
The second error you got is located at DB machine : you use a type IV driver (a 100% java driver) so your code comunicate directly with your db server via java sockets. The error is that no any is listening at server. You must start the server component in order to make communications. Do a netstat, or similar at server to see if there is a listening running up
Hope this helps
Hello I was reading the forum about the jdbc error in Tomcat and thought someone can help me with similar problem. I have installed DB2Connect driver 7.1, configured the database and test the connection successfully. Now I am trying to run an application in WSAD 4.0 in test server and gettign the following error:
2a71e5eb SystemOutU Throwing up - Datasource initialization failed: java.lang.UnsatisfiedLinkError: SQLAllocEnv
java.lang.UnsatisfiedLinkError: SQLAllocEnv
at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:228)
at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:118)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java:142)
at com.ssmb.recom.datamgr.RecomMultiDataSource.<init>(RecomMultiDataSource.java:98)
at com.ssmb.recom.datamgr.RecomDataSource.initialize(RecomDataSource.java:75)
at com.ssmb.recom.datamgr.RecomDataSource.<clinit>(RecomDataSource.java:52)
at com.ssmb.recom.datamgr.SiteUserData.<init>(SiteUserData.java:78)
at com.ssmb.recom.datamodel.User.<init>(User.java:47)
at com.ssmb.recom.datamodel.UserSession.<init>(UserSession.java:50)
I tried everythign possible. I added the db2java.zip to my server's class path and it still doesn't work. I know that the server and the db2 client are of the same version as my other applications on WSAD are working fine its just this particular application that complains.
Any help is appreciated.
it's the same reason as above:
The app-Driver needs a native library that is not installed on the server.
If you use that driver, it is not enough to include the java archive to the classpath. You have to install the DB2-Client software on the server and it will run.
It will run, unless the DB2-Server runs on IBM-Host (Version 7.x ). In this case use the universal-DB2 driver of IBM.
good luck!
hiiii
i hav created 1 JSF application in JSCreator and made a .war file to deploye it into tomcat 5.x.
i m using tomcat 5.x and DB2. I am facing some problem with 'net' driver of DB2.
as u suggested i have followed steps, but it gives exception as follows:
java.lang.RuntimeException: java.sql.SQLException: [IBM][JDBC Driver] CLI0639E Empty string.
at com.sun.data.provider.impl.CachedRowSetDataProvider.getMetaData(CachedRowSetDataProvider.java:1299)
at com.sun.data.provider.impl.CachedRowSetDataProvider.getFieldKeys(CachedRowSetDataProvider.java:485)
at com.sun.data.provider.impl.CachedRowSetDataProvider.getFieldKeyInternal(CachedRowSetDataProvider.java:463)
at com.sun.data.provider.impl.CachedRowSetDataProvider.getFieldKey(CachedRowSetDataProvider.java:440)
at com.sun.data.provider.impl.AbstractDataProvider.getValue(AbstractDataProvider.java:62)
at webapplication1.Country.prerender(Country.java:320)
at com.sun.web.ui.appbase.faces.ViewHandlerImpl.prerender(ViewHandlerImpl.java:788)
at com.sun.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:282)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:221)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.sun.web.ui.util.UploadFilter.doFilter(UploadFilter.java:179)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: [IBM][JDBC Driver] CLI0639E Empty string.
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.throwNullError(SQLExceptionGenerator.java:479)
at COM.ibm.db2.jdbc.net.DB2PreparedStatement.<init>(DB2PreparedStatement.java:286)
at COM.ibm.db2.jdbc.net.DB2PreparedStatement.<init>(DB2PreparedStatement.java:404)
at COM.ibm.db2.jdbc.net.DB2Connection.prepareStatement(DB2Connection.java:632)
at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:185)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:278)
at com.sun.sql.rowset.CachedRowSetXImpl.getMetaData(CachedRowSetXImpl.java:2335)
at com.sun.data.provider.impl.CachedRowSetDataProvider.getMetaData(CachedRowSetDataProvider.java:1297)
... 28 more
can any body help me out from this problem
thanx millions
ab
