I need to connect to a DB2 database server using jdbc
from Eclipse. Ev开发者_如何学编程en though I have already installed the required jar file, I am getting the following error:
Error occurred java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
Error occurred java.sql.SQLException: No suitable driver found for jdbc:db2://db2server
What do I do?
Thanks.
- Make sure the JAR containing com.ibm.db2.jcc.DB2Driver is in your CLASSPATH.
- If it is, check the URL syntax. That error usually means that the driver class was loaded, but the URL was incorrect. Here are the docs to show you what the correct syntax is.
- If both of those look right, make sure that the server name is visible from your machine. Ping that machine name; find out that you have it in your hosts table.
I had similar issue.
Well I tried to download IBM Driver and the Downloaded folder also contains db2jcc.jar and db2jcc4.jar put both these jars in WEB-INF/lib folder all do add them in classpath (Build path options). also your code must look something like this,
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
//context
//DataSource datasource = null;
// datasource = (DataSource)initCtx.lookup("jdbc:sqlserver://AZNICSQL02;DatabaseName=CIO;schemaName=dbo");
//Connect to Data source
dbconnection = DriverManager.getConnection("jdbc:db2://192.168.4.58:50001/", "", "");
dbstatement = (Statement) dbconnection.createStatement();`
Try exploring in DataSource Explorer plugin in eclipse
精彩评论