云静心舞

青青孜泾,悠悠我心

Tomcat+DB2的数据库连接池配置(转)

网上找到使用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

<Context displayName="ZJDII" docBase="zjdii" path="/zjdii">
  <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_zjdii_log." suffix=".txt" timestamp="true"/>
  <Resource auth="Container" name="jdbc/zjdii" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/zjdii">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:db2://192.168.200.113:6789/zjdii</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>yourpasswd</value>
    </parameter>
    <parameter>
      <name>maxWait</name>
      <value>1000</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>10</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>COM.ibm.db2.jdbc.net.DB2Driver</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>yourusername</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>30</value>
    </parameter>
  </ResourceParams>
</Context>

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

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里

posted on 2007-04-12 11:40 云静心舞 阅读(2498) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问