Here is the sample code which I am using from the JSP page
Context initContext = new InitialContext(); DataSource ds = (DataSource)initContext.lookup("jdbc/ams"); Connection con = ds.getConnection(); //Class.forName("com.ibm.db2.jcc.DB2ConnectionPoolDataSource"); Class.forName("COM.ibm.db2.jdbc.app.DB2Driver"); // Connection con; //step 2 Creation of a connection thru JDBC Driver Instance con = DriverManager.getConnection("jdbc b2:AMS_DB", "db2inst1","db2inst1"); //step 3 Creation of one or more statements using the RDBMS connection Statement stmt = con.createStatement(); .... ....
(1) The link difficulty with the shared library occurs because you're not using a type IV JDBC driver. I'm sure there's a 100% Java driver for DB2. That will eliminate the need for a shared library link.
(2) I see "No suitable driver" error when the JVM has successfully loaded the driver class but I've made an error in the syntax for the connection URL. Check your syntax to eliminate that problem.
I connect via type 4 driver. But my goal is to use type 2. I have DB2 8.2 runtime client on my PC, DB2 8.2 personal on other.
I have DB2 alias:
--------------------------------------------------- db2 => LIST DATABASE DIRECTORY
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = RBCX Database name = RBCX Node name = DB2TCP15 Database release level = a.00 Comment = Directory entry type = Remote Authentication = SERVER Catalog database partition number = -1 Alternate server hostname = Alternate server port number =
You are running into this problem because there are two classpaths you are dealing with. You database driver needs to be in the Java classpath to compile, and your Web servers classpath for execution.
Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Joined: Feb 09, 2005
Thanks for fast response. Please explain me, what does it mean "2 classpathes".
I test my connection without any container (you noticed about web container), just via POC (pure old console). As I know, because jdbc driver classes are loaded dynamically, they need not be added in classpath while source code compilation.
I've read from several sources, that problem can be in connection url syntax and driver mismatch. To be honest, in this case to make mistake is a rather hard (but may be I did..but where?). To avoid any flaws like this I construct my classpath as you can see here (env.bat): --------------------------------------------- @echo off
set APP_HOME=. set APP=%APP_HOME%/jdbc-connect-test-1.0.jar set APP_LAUNCHER_CLASS=com.infy.jdbc.JDBCRequestor set LIB_HOME=%APP_HOME%/lib
@rem For DB2 7: set DB2_LIB=%LIB_HOME%/db2java.zip
set DB2INSTANCE=C:/IBM/SQLLIB set DB2_DRIVER_PATH=%DB2INSTANCE%/java/db2java.zip
@rem set PATH=%DB2INSTANCE%\bin;%PATH%
set XERCES=%LIB_HOME%/axerces.jar set LOG=%LIB_HOME%/log4j-1.2.9.jar
set JAVA=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\jre\lib\rt.jar; set CPATH=%APP_HOME%;%APP%;%LOG%;%DB2_LIB%;%XERCES%;%JAVA% ---------------------------------------------
PATH has path to sqllib but apparently not being parsed by IBM properly. Apparently the space between "Program Files" causes it to fail. Launch from sqllib\bin folder and it works. Oh, here's some code that helps but still really doesn't point out the problem:
Nothing's more frustrating than someone who asked for help in a forum - then finds a solution - tells every one he has solved the issue - but does not share how he solved it with the rest of the community.
I am wrestling with the same issue - a couple of minutes of time taken to post his solution - would have saved me days... I will post the solution when I get there.
I am using the Spring Ibatis framework to get to DB2. I get an abstractMethodError when using the older db2 7.1 driver (on a gettype method on a resultset implementation) . When I switch to JDBC type4 driver - i get the "no Suitable Driver" error.
Joined: Feb 09, 2005
============== Nothing's more frustrating than someone who asked for help in a forum - then finds a solution - tells every one he has solved the issue - but does not share how he solved it with the rest of the community. ============== Oh, I clearly see your point. As for me, if it was solution of this particular problem, I'd gladly shared it with anyone. But the goal of my work was not solve this particular task (connect to db2 7 by using db8 type2 or 4 drivers), but to find any means to connect db7 (client uses this version and it was even a bit stupid for me to try using db2 8 driver). Eventually I just installed db2 7 client, installed db2 7 server (forgot about db2 8), started using db2 7 driver and all simply worked. To explain this administrative (not technology) solutuion - I didn't see too many reasons. Sorry, if I mislead you.
This may be a little late for some of the previous posters, but here's for people who may be having problems with this in the future...
Don't use the driver in 'db2java.zip' file (COM.ibm.db2.jdbc.app.DB2Driver). This driver tries to load a C library file (probably for a Unix) environment.
So you probably need to set LD_LIBRARY_PATH and such.
Use (com.ibm.db2.jcc.DB2Driver) in 'db2cc.jar' instead.
subject: java.sql.SQLException: No suitable driver