public Statement createStatement()
throws SQLException
Retrieves whether this Connection object has been closed. A connection is closed if the method close has been called on it or if certain fatal errors have occurred. This method is guaranteed to return true only when it is called after the method Connection.close has been called.
This method generally cannot be called to determine whether a connection to a database is valid or invalid. A typical client can determine that a connection is invalid by catching any exceptions that might be thrown when an operation is attempted.
/**
建构函数私有以防止其它对象创建本类实例
*/
public DBConnectionManager()
{
init();
}
/** Added by leo on 2001-5-23
使用默认的连接池名,创建并返回新连接
*
* @return Connection 可用连接或null
*/
public Connection getConnection()
{
return getConnection(DEFAULTCONNECTIONPOOL);
}
/**
获得一个可用连接.若没有可用连接,且已有连接数小于最大连接数限制,
则创建并返回新连接.否则,在指定的时间内等待其它线程释放连接.
*
* @param name 连接池名字
* @param time 以毫秒计的等待时间
* @return Connection 可用连接或null
*/
public Connection getConnection(String name, long time)
{
DBConnectionPool pool = (DBConnectionPool)pools.get(name);
if(pool != null)
{
return pool.getConnection(time);
}
return null;
}
/** Added by leo on 2001-5-23
将连接对象返回给默认的连接池
*
* @param con 连接对象
*/
public void freeConnection(Connection con)
{
String name = DEFAULTCONNECTIONPOOL;
freeConnection(name,con);
}
/**
将连接对象返回给由名字指定的连接池
*
* @param name 在属性文件中定义的连接池名字
* @param con 连接对象
*/
public void freeConnection(String name, Connection con)
{
DBConnectionPool pool = (DBConnectionPool)pools.get(name);
if(pool != null)
{
pool.freeConnection(con);
}
}