Tomcat+DB2数据库连接池设置

 

该篇文章是最近做公司项目的时候测试所用,网上找N多资料,发现许多是挂羊头卖狗肉,所以特地贴此文章,以免他人误入歧途~!!

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里

 

你可能感兴趣的:(Tomcat+DB2数据库连接池设置)