首页 > 数据库 > DB2 > 正文

db2的jdbc连接

2020-03-09 22:29:54
字体:
来源:转载
供稿:网友

   1:如果数据库为db2,则你所要查找的表前面要加上这个建表的用户名,
      如,testtable这张表,我是通过系统登陆的帐号所建,为lixc.testtable;
      我所使用查询的用户为admin,如果你只是写select * from testtable ,则
      db2只是默认的查找admin.testtable,这张表不存在,所以应该写为:
      select * from lixc.testtable
   2: 如果你连接数据库的url和drivername都是通过配置文件*.properties来读取的
      话,则要注意: 如drivermanager:com.ibm.db2.jcc.db2driver,如果其后面还有
      空格的话,可能在java运行的时候会出现,com/ibm/db2/jcc/db2driver这个class文件
      找不到的错误。我曾经遇到这个情况,如果直接在class.forname("drivername").newinstance();
      测试成功,可是读取配置文件class.forname(driverstr).newinstance();则是报以上错误。
      后来将配置文件中后面的空格去掉,程序运行成功。

db2的jdbc连接用法:
 1. 将 db2jcc.jar 和 db2jcc_license_cu.jar 配置在环境变量classpath下。

 2. 将 db2jcc.jar 和 db2jcc_license_cu.jar复制在你所用的应用服务器中工程下的web-inf/lib包下

 3. jdbc url :jdbc:db2://tdurden:50000/sample
 ( where tdurden is the machine the db2 database server resides on and where sample is the database instance - 50000 is the default db2 port to connect to )

 4.  driver class field: com.ibm.db2.jcc.db2driver

 5. add a valid username and password in the username and password fields.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表