Chinaorg

于千万人之中,遇见你所遇见的人;于千万年之中,时间的无涯荒野里,没有早一步,也没有晚一步,刚巧赶上了
我不去想是否能够成功,既然选择了远方,便只顾风雨兼程; 我不去想,身后会不会袭来寒风冷雨,既然目标是地平线,留给世界的只能是背影
posts - 20, comments - 6, trackbacks - 0, articles - 0

配置连接池(终于弄好了~~)

Posted on 2006-10-09 01:05 chinaorg 阅读(165) 评论(0)  编辑  收藏 所属分类: JAVA/JSP

server.xml

 <Context path="/bookstore" docBase="bookstore" debug="0"     reloadable="true">

     <Resource
         name="jdbc/BookDB" 
         auth="Container"
         type="javax.sql.DataSource"
         driverClassName="com.mysql.jdbc.Driver" 
         maxActive="100"
         maxIdle="30" maxWait="10000"
         url="jdbc:mysql://localhost:3306/bookdb?autoReconnect=true"
         username="dbuser" 
         password="1234" 
         removeAbandoned="true"/>

    </Context>




web.xml

<?xml version="1.0" encoding="UTF-8"?>
   <web-app>
    <welcome-file-list>
        <welcome-file>Dbjsp1.jsp</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 <resource-ref>
  <description>DB connection</description>
  <res-ref-name>jdbc/BookDB</res-ref-name>
  <res-type>javax.sql.Datasource</res-type>
  <res-auth>Container</res-auth>
  <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>
</web-app>



//数据库连接代码

  Connection con;
  Statement stmt;
  ResultSet rs;
  
  Context ctx=new InitialContext();
  DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/BookDB");
  con=ds.getConnection();
  
  stmt=con.createStatement();



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


网站导航: