Eclipse 中使用 JDBC 的 DB2 连接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5546424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DB2 Connection Issue using JDBC from eclipse
提问by Sayyid
I need to connect to a DB2 database server using jdbc
from Eclipse. Even though I have already installed the required jar file, I am getting the following error:
我需要使用jdbc
Eclipse连接到 DB2 数据库服务器。即使我已经安装了所需的 jar 文件,我仍然收到以下错误:
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.
谢谢。
回答by duffymo
- 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. Hereare 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.
- 确保包含 com.ibm.db2.jcc.DB2Driver 的 JAR 在您的 CLASSPATH 中。
- 如果是,请检查 URL 语法。该错误通常意味着驱动程序类已加载,但 URL 不正确。 以下是向您展示正确语法的文档。
- 如果这两个看起来都正确,请确保服务器名称在您的机器上可见。ping那个机器名;发现你的主机表中有它。
回答by tosha Shah
I had similar issue.
我有类似的问题。
Well I tried to download IBM Driverand the Downloaded folder also contains db2jcc.jarand db2jcc4.jarput both these jars in WEB-INF/libfolder all do add them in classpath (Build path options). also your code must look something like this,
好吧,我尝试下载IBM Driver,Downloaded 文件夹中还包含db2jcc.jar和db2jcc4.jar,将这两个 jar 放在WEB-INF/lib文件夹中,都将它们添加到类路径中(构建路径选项)。你的代码也必须是这样的,
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 pluginin eclipse
尝试在 Eclipse中的DataSource Explorer 插件中进行探索