[英]No suitable driver found error for odbc, db2
I'm trying to connect to a remote database using the following java code, but I get an error saying no suitable driver found. 我正在尝试使用以下Java代码连接到远程数据库,但出现错误,提示找不到合适的驱动程序。
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 1.您必须先加载驱动程序,然后才能使用它
2. If I am not mistaken, the driver you are loading is a JDBC driver for DB2 UDB, not ODBC . 2.如果我没记错的话,您正在加载的驱动程序是DB2 UDB的JDBC驱动程序,而不是ODBC 。 The connection URL for it is "jdbc:db2//host:port/database"
它的连接URL是“ 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文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.