db2 jdbc 连接池_Tomcat+DB2的数据库连接池配置(转)

本文详细介绍了如何在Windows 2000环境下,使用Tomcat 5.0.16与DB2 v8.1.0.96数据库建立JDBC连接池的步骤,包括所需的JDBC驱动复制、classpath设置以及可能出现的错误及解决方案。
摘要由CSDN通过智能技术生成

网上找到使用TOMCAT配置DB2的资料很少,很多人挂“羊头“卖“狗肉”,这是老大花了一定的时间研究之后才搞定的,所以发出来避免大家走弯路,虽然是转载,希望能发到首页,避免大家走弯路

转自老大的blog,顺便打打广告http://163hbfang.blog.163.com/blog/static/2448133200621134590/

上面还是有很多有技术价值的东西,不过因为在163所以很少人光顾,帮他打广告^_^

1、操作系统Windows2000(经测试,在Linux不需操作第6点)

2、Tomcat版本:Apache Tomcat/5.0.16

3、JDK版本:j2sdk1.4.1_03

4、DB2版本:使用db2inst1用户输入db2level命令得到:DB2 v8.1.0.96,修订包为"10"

5、在安装DB2的机器上/opt/IBM/db2/V8.1/java目录下拷贝db2java.zip、db2jcc.jar到$CATALINA_HOME/common/lib下,并重命名db2java.zip为db2java.jar

6、把db2java.jar加classpath

.;C:\j2sdk1.4.1_03\lib\dt.jar;D:\tomcat5\common\lib\db2jcc.jar;D:\tomcat5\common\lib\db2java.jar;

7、手工配置zjdii.xml,不要在$CATALINA_HOME/conf/server.xml修改任何信息;在$CATALINA_HOME/conf/localhost下修改或新建zjdii.xml

factory

org.apache.commons.dbcp.BasicDataSourceFactory

url

jdbc:db2://192.168.200.113:6789/zjdii

password

yourpasswd

maxWait

1000

maxActive

10

driverClassName

COM.ibm.db2.jdbc.net.DB2Driver

username

yourusername

maxIdle

30

常见错误信息及解决方案:

org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'COM.i

bm.db2.jdbc.net.DB2Driver', cause:

java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.net.DB2Driver

at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClas

sLoader.java:891)

at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClas

sLoader.java:756)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:140)

at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou

rce.java:730)

at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource

.java:518)

at com.zjdii.db.DataBase.getConnection(Database.java:44)

at com.zjdii.db.DBFactory.getPreparedStatement(DBFactory.java:86)

at org.apache.jsp.test.clob.clob_jsp._jspService(clob_jsp.java:50)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper

.java:311)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3

01)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:284)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:204)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV

alve.java:256)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv

eContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav

a:564)

at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard

ContextValve.java:245)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV

alve.java:199)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv

eContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav

a:564)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j

ava:195)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv

eContext.java:151)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j

ava:164)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv

eContext.java:149)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav

a:564)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal

ve.java:156)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv

eContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav

a:564)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:21

1)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java

:805)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce

ssConnection(Http11Protocol.java:696)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java

:605)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP

ool.java:677)

at java.lang.Thread.run(Thread.java:536)

java.lang.NullPointerException

解决方案:

把D:\tomcat5\webapps\common\lib\db2java.jar;加入classpath里

javax.servlet.ServletException: com/ibm/db2/jcc/SQLJPackage

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)

org.apache.jsp.test.clob.clob_jsp._jspService(clob_jsp.java:82)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.lang.NoClassDefFoundError: com/ibm/db2/jcc/SQLJPackage

COM.ibm.db2.jdbc.net.DB2Connection.prepareStatement(DB2Connection.java:627)

org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:216)

org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:323)

com.zjdii.db.DBFactory.getPreparedStatement(DBFactory.java:167)

org.apache.jsp.test.clob.clob_jsp._jspService(clob_jsp.java:50)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.

解决方案:

把D:\tomcat5\webapps\common\lib\db2jcc.jar;加入classpath里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值