使用DBCP连接池得不到记录,而用DBPool却可以
package dbpooltest;
import java.sql.*;
import snaq.db.ConnectionPoolManager;     
import org.apache.commons.dbcp.BasicDataSource;     
/**
 * 
 * @author lzk
 * 2008-8-25 下午01:49:50
 * @随机查询的实现
 */
public class SelectS {
private static Connection con = null;
private static PreparedStatement pstmt = null;
private static ResultSet rs = null;


public static Connection getDBPoolcon(){   //DBPool连接池
ConnectionPoolManager cpm = null;
Connection con = null;
long timeout = 2000;  
try{
cpm = ConnectionPoolManager.getInstance("dbpool.properties");
}catch (Exception e){
System.out.println("Error Connection.getconnection(): "+e.getMessage());
}

try{
con = cpm.getConnection("localpool", timeout);
}catch (SQLException sqle){
System.out.println(sqle.getMessage());
}

return con;
}

public static Connection getDBCPcon(){   //dbcp连接池
Connection con  = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String URL = "jdbc:sqlserver://192.168.168.104:1433;DatabaseName=LTest";
BasicDataSource bds = new BasicDataSource();

try{
bds.setDriverClassName(driver);
bds.setUrl(URL);
bds.setUsername("sa");
bds.setPassword("ba123");
bds.setMaxActive( 50 );    //设置最大活动连接
bds.setMaxIdle( 10 );      //最大空闲连接
bds.setMaxWait( 10000 );   //最大等待时间
}catch(Exception e){
System.out.println("Error setConnection: "+e.getMessage());
}

try{
con = bds.getConnection();
}catch(Exception e){
System.out.println("Error getConnection:"+e.getMessage());
}
return con;
}
public static void main(String args[]) throws Exception{
PreparedStatement pstmt = null; SelectS ss = new SelectS();
Connection DBPoolconn = ss.getDBPoolcon();
Connection dbcpconn = ss.getDBCPcon();
//System.out.println(dbcpconn);

for(int i=0; i<10; i++){     
String selectSQL = "SELECT * FROM tablea_1 where num =?";
pstmt = dbcpconn.prepareStatement(selectSQL);
//pstmt = DBPoolconn.prepareStatement(selectSQL);
pstmt.setInt(1, i);
rs = pstmt.executeQuery();

while(rs.next()){
System.out.print(rs.getString(1)+" ");
System.out.println(rs.getString(2));
}
}
}
}程序可以正常运行,但就是不知道为什么得不到记录,用DBPool就可以得到记录;
但使用System.out.println(dbcpconn);打印的结果是:
jdbc:sqlserver://192.168.168.104:1433;responseBuffering=full;encrypt=false;databaseName=LTest;selectMethod=direct;trustServerCertificate=false;lastUpdateCount=true;, UserName=sa, Microsoft SQL Server 2005 JDBC Driver