Are you loading the driver directly or using a data source? If the former, does your driver load successfully? Is the driver on your classpath? The following is the code that I use to load a driver to connect to DB2 v7.1 for NT. I use the DSN name in the url but it matches my db and alias names as well. Connection con1 = null;
String url = "jdbc:db2:MyDSN";
String user = "myuser";
String pwd = "mypwd";
try {
// load IBM driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
} catch (ClassNotFoundException e) {
System.out.println( "Class not found: " + e.getMessage() );
System.exit(-1);
} try {
// connect to the database
con1 = DriverManager.getConnection(url, user, pwd);
} catch (SQLException ex) {}
String url = "jdbc:db2:MyDSN";
String user = "myuser";
String pwd = "mypwd";
try {
// load IBM driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
} catch (ClassNotFoundException e) {
System.out.println( "Class not found: " + e.getMessage() );
System.exit(-1);
} try {
// connect to the database
con1 = DriverManager.getConnection(url, user, pwd);
} catch (SQLException ex) {}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货