在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;
}