jdbc+oracle!请教!

snatch 2003-03-25 08:49:33
bundle=ResourceBundle.getBundle("DataSource");
try{
//create and store parameters which are used to create the context
Hashtable env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,bundle.getString("datasource.factory"));
env.put(Context.PROVIDER_URL,bundle.getString("datasource.url"));
//create a context
Context context=new InitialContext(env);
//create a DataSource object
OracleConnectionPoolDataSource dataSource = new OracleConnectionPoolDataSource();
//set the connection parameters
String s=bundle.getString("datasource.username");
dataSource.setUser(s);
s=bundle.getString("datasource.password");
dataSource.setPassword(s);
s=bundle.getString("datasource.drivertype");
dataSource.setDriverType(s);
s=bundle.getString("datasource.netprotocol");
dataSource.setNetworkProtocol(s);
s=bundle.getString("datasource.server");
dataSource.setServerName(s);
dataSource.setPortNumber(getPort());
s=bundle.getString("datasource.databasename");
dataSource.setDatabaseName(s);
//int n=dataSource.getActiveSize();
//get the bind name
String bindName=bundle.getString("datasource.bindname");
//bind the DataSource with the name
context.rebind(bindName,dataSource);
System.out.println("DataSource completed");
}
请问一下,在OracleConnectionPoolDataSource中有没有方法可以设置pool的size?
为什么在api说明中没有该类函数?有什么方法可以控制pool呢?
...全文
9 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sparkwu 2003-03-26
Reference:
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;
import java.sql.*;


public class GonehomeDBPool extends Object
{
private static GonehomeDBPool pool = null;
private OracleConnectionCacheImpl myConnectionPool=null;
private OracleConnectionPoolDataSource myDataSource=null;

private GonehomeDBPool()
{
try{
//Create oracle datasource instance
myDataSource = new OracleConnectionPoolDataSource();
// Set connection parameters
myDataSource.setDriverType("thin");
myDataSource.setNetworkProtocol("tcp");
myDataSource.setServerName("ipaddress");
myDataSource.setDatabaseName("xxxx");
myDataSource.setPortNumber(1521);
myDataSource.setUser("xxxx");
myDataSource.setPassword("xxx");

//Create & configure pool
myConnectionPool = new OracleConnectionCacheImpl(myDataSource);
myConnectionPool.setMaxLimit(10);
myConnectionPool.setMinLimit(3);


myConnectionPool.setCacheScheme(OracleConnectionCacheImpl.FIXED_RETURN_NULL_SCHEME);

}catch (Exception ex)
{
System.out.println("GonehomeDBPool()- Exception catched :"+ex);
}
}
public static GonehomeDBPool getPool()
{
if(pool == null)
{
pool=new GonehomeDBPool();
System.out.println("GonehomeDBPool getPool()==="+pool);
}
return pool;
}
public Connection getDatabaseConnection()
{
try{
return (Connection)myConnectionPool.getConnection();
}
catch (Exception exp)
{
System.out.println("getDatabaseConnection()=="+exp);
return null;
}
}
public static void closeConnection(Connection connection)
{
try{
connection.close();
}catch (Throwable exep)
{
System.out.println("closeDatabaseConnection(connection) - Exception catched: " +exep);
}
}
public int getActiveNumberOfConnections()
{
return myConnectionPool.getActiveSize();
}

public int getCacheNumberOfConnections()
{
return myConnectionPool.getCacheSize();
}

}
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-03-25 08:49
社区公告
暂无公告