为什么我的数据库中锁的记录很多,不会是我的语句有问题吧
yown 2005-09-30 04:43:28
为什么我的数据库中锁的记录很多,不会是我的语句有问题吧
数据库:sqlserver2000
tomact4.0.1版
Jdbc:Microsoft SQL Server 2000 Driver for JDBC
我这样查询的
select * from master..sysprocesses
where hostname='mg' and lastwaittype='writelog'
结果
spid waittype lastwaittype
51 0x0000 WRITELOG
53 0x0000 WRITELOG
....
发现记录有30000多条,其中大部分记录一直占有,直到tomcat不能连接数据库了,在数据库的日志中出现:连接数达到最大值
Tomcat就不能连接数据库了而不得不重启tomcat,重启后就上面的锁记录就释放了,又可正常访问,可就过几个小时又出现这个情况了
这是网站的首页要调用的jsp中访问数据库的代码,首页访问量每小时在40000左右
-------------------------------------------------------------------------
....
String userID=request.getParamter("uid");
Connection conn = null;
ResultSet rset=null;
Statement stmt=null;
try
{
conn = ConnectionPool.getConnection (); //这是从连接池中取一个连接
StringBuffer sb = new StringBuffer ();
sb.append ("select a.SID, a.mobileNumber, a.mobileType, b.username from userInfo a, userRegisterinfo b where a.SID=b.userID and b.userID =");
sb.append (userID);
stmt = conn.createStatement();
rset=stmt.executeQuery (sb.toString ());
if (rset.next ())
{
StringBuffer sb2 = new StringBuffer ();
sb2.append ("update userinfo set lastLoginTime= getdate()");
sb2.append (" where SID=");
sb2.append (userID);
stmt.executeUpdate (sb2.toString ());
}
}
catch (Exception e)
{
}
finally
{
try
{
if (rset!=null) rset.close();
if (stmt!=null) stmt.close();
ConnectionPool.release (conn);//释放本连接到连接池
}catch (Exception e2) {}
}
.........
请各位帮我呀,万分感谢!
请给出解决方案!
这是我的另外一贴
http://community.csdn.net/Expert/topic/4304/4304422.xml?temp=.9371454