java 使用 jt400.jar 建立到 db2 的连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28401370/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:32:43  来源:igfitidea点击:

Establish connection to db2 using the jt400.jar

javajdbcdb2jt400jtopen

提问by aeycee

I have tried using the db2jcc.jar and I successfully establish connection to db2 but now I am trying to use the jt400.jar

我曾尝试使用 db2jcc.jar 并成功建立到 db2 的连接,但现在我正在尝试使用 jt400.jar

I have tried to use the driver com.ibm.db2.jdbc.app.DB2Driver but I keep getting the class not found exception.

我曾尝试使用驱动程序 com.ibm.db2.jdbc.app.DB2Driver,但我不断收到找不到类的异常。

I tried using the com.ibm.as400.access.AS400JDBCDriver but I can't establish connection.

我尝试使用 com.ibm.as400.access.AS400JDBCDriver 但我无法建立连接。

Can anyone help me or provide a sample code with the connection string connecting to a db2 with jt400.jar.

任何人都可以帮助我或提供带有连接字符串的示例代码,该连接字符串使用 jt400.jar 连接到 db2。

Class.forName("com.ibm.as400.access.AS400JDBCDriver");
Properties prop = new Properties();

prop.setProperty("user", "current");
prop.setProperty("password", "current");

con = DriverManager.getConnection("jdbc:as400://server/database", prop);

回答by YLombardi

I use this code to connect to my db2 database with jt400 :

我使用此代码通过 jt400 连接到我的 db2 数据库:

Class.forName("com.ibm.as400.access.AS400JDBCDriver");
        connection = DriverManager.getConnection(
                "jdbc:as400:" + iseries + ";database name=" + iasp + ";prompt=false;translate binary=true;naming=system", login, password);

For exemple, if I try to connect to the server "server1" and the database "database1", the url is "jdbc:as400:server1;database name=database1;prompt=false;translate binary=true;naming=system"

例如,如果我尝试连接到服务器“server1”和数据库“database1”,则 url 为“jdbc:as400:server1;database name=database1;prompt=false;translate binary=true;naming=system”

回答by Amaury Valdes

I know I am late to this party but just wanted to point out a tutorial that might aid others when using Spring Framework and connecting to a DB2 dataSource. In my example, I was using Tomcat Server but it should be applicable to other web servers as well. Anyways, I hope this helps: https://avaldes.com/spring-mvc-with-jndi-datasource-for-db2-on-as400-using-tomcat/

我知道我参加这个聚会迟到了,但只是想指出一个在使用 Spring Framework 和连接到 DB2 数据源时可能会帮助其他人的教程。在我的示例中,我使用的是 Tomcat 服务器,但它也应该适用于其他 Web 服务器。无论如何,我希望这会有所帮助:https: //avaldes.com/spring-mvc-with-jndi-datasource-for-db2-on-as400-using-tomcat/