CSDN博客

img wx2001

jbuilder中配置tomcat数据库连接池的方法

发表于2004/11/3 1:13:00  2564人阅读

在JBuilder里配置Tomcat4.1.24过程

1.在JBuilder9程序目录下有个thirdparty/jakarta-tomcat-4.1.24-LE-jdk14目录,这就是JBuilder自带的Tomcat4.1服务器
2.数据库连接池需要commons-dbcp-1.1,commons-pool-1.1这两个jar包 ,jb下的toncat没有自带这个两个jar包, 把它们copy到JBuilder9程序目录下的thirdparty/jakarta-tomcat-4.1.24-LE-jdk14//common/lib
3.把JDBC驱动程序COPY到JBuilder9程序目录下的thirdparty/jakarta-tomcat-4.1.24-LE-jdk14//common/lib里
4.你的project下面有Tomcat的目录,进去后会看到conf,webapp和work三个文件夹。仔细看看conf何webapp里面的配置文件,修改webapp里面的jb****.xml(****是虚拟路径名),反以下内容的注释去掉<!--This comment marks this file as generated, so it may be deleted and regenerated at any time. To preserve manual changes to this file, delete this comment.--> 然后配置数据库连接池
5.我的jb****.xml例子
<?xml version="1.0" encoding="UTF-8"?>
<Context debug="0" docBase="D:/Application/application" path="/application" reloadable="true" workDir="D:/Application/Tomcat/work/application">

  <Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/connectDB">
    <parameter>
      <name>factory</name>
      <!--DBCP Basic Datasource Factory -->
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter> 
    <parameter>
      <name>driverClassName</name>
      <!-- Database Driver Class Name -->
      <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
      <name>url</name>
      <!-- Database Address -->
      <value>jdbc:mysql://localhost/smsdata</value>
    </parameter>
    <parameter>
      <name>username</name>
      <!-- Database User Name -->
      <value>root</value>
    </parameter>
    <parameter>
      <name>password</name>
      <!-- User Password -->
      <value></value>
    </parameter> 
    <parameter>
      <name>maxActive</name>
      <!-- Maximum number of DB connections in pool.Set to 0 for no limit. -->
      <value>20</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <!-- Maximum number of idle DB connections to retain in pool.Set to 0 for no limit. -->
      <value>0</value>
    </parameter>
    <parameter>
      <name>maxWait</name>
      <!-- Maximum time to wait for a DB connection to become available in ms.An exception is thrown if this timeout is exceeded.Set to -1 to wait indefinitely. -->
      <value>-1</value>
    </parameter>
    <parameter>
      <name>removeAbandoned</name>
      <!-- Abandoned DB connections are removed and recycled -->
      <value>true</value>
    </parameter>
    <parameter>
      <name>logAbandoned</name>
      <!-- Log a stack trace of the code which abandoned -->
      <value>false</value>
    </parameter> 
   
  </ResourceParams>
</Context>

6.JSP测试连接池例子
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*"%>
<%!
  Connection conn= null;
%>

<%

  Context ctx = null;
  try {
    ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");
    conn = ds.getConnection();

  }
  finally {
    try {
      if (ctx!=null) {
        ctx.close();
      }
    }
    catch (NamingException) {}
  }

 

%>

阅读全文
0 0

相关文章推荐

img
取 消
img