resin连接池配置(jtds)以及java类

在resin-conf-resin.conf下找到连接池配置 :

          <database>
          <jndi-name>jdbc/testbase</jndi-name>
           <driver type="net.sourceforge.jtds.jdbc.Driver">
             <url>jdbc:jtds:sqlserver://localhost:1433;DatabaseName=data</url>
             <user>yjw</user>
             <password>8125296</password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>

 

java实现类:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.CallableStatement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class ConnectBean {
    //========================================================
 //Comment   :链接连接池(static,启动服务器自动加载)
 //Author    :yjw
 //Update    :2007-12-24 08:09:00
    //========================================================
 
  
     private static DataSource pool;
     static {
         Context env = null;
         try {
             env = (Context) new InitialContext();
             pool = (DataSource) env.lookup("java:comp/env/jdbc/testbase");
            
         } catch (NamingException e) {
             if (pool == null) {
              System.out.println("the jdbc/mysql is null");
             }
             System.out.println(e.getLocalizedMessage());
         }
     }
     //========================================================
  //Comment   :链接数据库
  //Parameter :无
  //Returns   :Connection
  //Author    :yjw
  //Update    :2007-12-24 08:09:00
     //========================================================
     public static Connection getConnection() {
         Connection conn = null;
         MyLog mylog = new MyLog();
         if (pool != null) {
             try {
                 conn = pool.getConnection();
             } catch (SQLException e) {
              mylog.setMsg(e.getLocalizedMessage());
             }
         }
         return conn;
     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值