I'm trying to connect to a remote database using the following java code, but I get an error saying no suitable driver found.
DriverManager.getConnection("odbc:db2://url:port/dbname");
Class.forName("com.ibm.db2.jcc.DB2Driver");
What could I be doing wrong?
Two comments:
1. You have to load the driver first, before trying to use it
2. If I am not mistaken, the driver you are loading is a JDBC driver for DB2 UDB, not ODBC . The connection URL for it is "jdbc:db2//host:port/database"
So your code should look something like this:
Class.forName("com.ibm.db2.jcc.DB2Driver");
DriverManager.getConnection("jdbc:db2://host_or_ip_address:port/dbname");
我找到了解决方案...我没有为驱动程序添加JAR文件。
您应该将db2cc.jar,db2jcc_license_cu.jar和db2jcc_license_cisuz.jar文件的jar文件添加到类路径位置,并且将这些jar文件保存在db2安装目录位置的java文件夹下,您得到了上述jar文件
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.