up up
不知道你是不是原创了许多啦。
不知道你是不是原创了许多啦。
解决方案 »
- Eclipse3.5 jsp插入Java代码不自动提示
- 请问关于由数据显示图片的问题,以下是我的代码,其中img是图片数据
- tomcat5.0 做web服务器时,+webwork +hibernet 文件被解析成乱码
- TOMCAT服务器的session对象持久化技术
- 找工作光有技术 还不够 我的郁闷 散分!!!!!
- 有关URL的一个问题
- 关于apache的配置问题
- 怎样才能得到行的总数
- jsp中能调用pl/sql存储过程吗?
- 项目登录时报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException
- 请解决一下下面的小问题!
- applet与servlet实时数据交互的问题
} /**
* 从连接池获得一个可用连接.如没有空闲的连接且当前连接数小于最大连接
* 数限制,则创建新连接.如原来登记为可用的连接不再有效,则从向量删除之,
* 然后递归调用自己以尝试新的可用连接.
*/
public synchronized Connection getConnection()
{
Connection con = null;
if (freeConnections.size() > 0)
{
// 获取向量中第一个可用连接
con = (Connection) freeConnections.firstElement();
freeConnections.removeElementAt(0);
try
{
if (con.isClosed())
{
log("从连接池" + name+"删除一个无效连接");
// 递归调用自己,尝试再次获取可用连接
con = getConnection();
}
}
catch (SQLException e)
{
log("从连接池" + name+"删除一个无效连接");
// 递归调用自己,尝试再次获取可用连接
con = getConnection();
}
}
else if (maxConn == 0 || checkedOut < maxConn)
{
con = newConnection();
}
if (con != null)
{
checkedOut++;
}
return con;
} /**
* 从连接池获取可用连接.可以指定客户程序能够等待的最长时间
* 参见前一个getConnection()方法.
*
* @param timeout 以毫秒计的等待时间限制
*/
public synchronized Connection getConnection(long timeout)
{
long startTime = new Date().getTime();
Connection con;
while ((con = getConnection()) == null)
{
try
{
wait(timeout);
}
catch (InterruptedException e)
{}
if ((new Date().getTime() - startTime) >= timeout)
{
// wait()返回的原因是超时
return null;
}
}
return con;
} /**
* 关闭所有连接
*/
public synchronized void release()
{
Enumeration allConnections = freeConnections.elements();
while (allConnections.hasMoreElements())
{
Connection con = (Connection) allConnections.nextElement();
try
{
con.close();
log("关闭连接池" + name+"中的一个连接");
}
catch (SQLException e)
{
log(e, "无法关闭连接池" + name+"中的连接");
}
}
freeConnections.removeAllElements();
} /**
326 * 创建新的连接
327 */
private Connection newConnection()
{
Connection con = null;
try
{
if (user == null)
{
con = DriverManager.getConnection(URL);
}
else
{
con = DriverManager.getConnection(URL, user, password);
}
log("连接池" + name+"创建一个新的连接");
}
catch (SQLException e)
{
log(e, "无法创建下列URL的连接: " + URL);
return null;
}
return con;
}
}
}