如何加入数据连接池?[在线等]
下面是数据库连接,现在挂在网上可以使有使用。但是老是点资源过多。数据库连接过多。后来听说要写数据连接池,请问在这样的情况下如何加入数据连接池?有朋友懂?
______________________________________________
package db;
import java.sql.*;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class DbManager {
//String strurl= "jdbc:odbc:coursetable ";
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
//String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver ";
String sConnStr = "jdbc:microsoft:sqlserver://xxxx:1433;DatabaseName=xxxx ";
String user= "xxx ";
String password= "xxx ";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public DbManager()
{
try{
Class.forName(sDBDriver);
}
catch(
java.lang.ClassNotFoundException e){
System.err.println( "opendb(): " + e.getMessage());
}
}
// 返回数据库连接对象
public Connection Creatconn(){
conn = null;
try{
conn=DriverManager.getConnection(sConnStr,user,password);
return conn;
}
catch(Exception fe){
System.err.println( "Creatconn(): " + fe.getMessage());
return null;
}
}
// 返回状态集对象
public Statement CreatStat(){
stmt = null;
try{
if(conn==null)
{
conn=this.Creatconn();
}
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
return stmt;
}
catch(Exception fe){
System.err.println( "CreatStat(): " + fe.getMessage());
return null;
}
}
// 返回记录集对象
public ResultSet getResult(String sql){
rs = null;
try{
stmt = this.CreatStat();
rs = stmt.executeQuery(sql);
return rs;
}
catch(
SQLException ex){
System.err.println( "getResult: " + ex.getMessage(