为什么我的数据库中锁的记录很多,不会是我的语句有问题吧

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
...全文
230 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
clop 2005-09-30
  • 打赏
  • 举报
回复
关键是锁的原因,因为锁做成你的SQL无法执行,而占用连接池的连接,知道到达连接池数量

你关键要找到锁的源头,用sp_who找到引起锁的进程,查看其执行语句

找到对应的程序进行修正
vivianfdlpw 2005-09-30
  • 打赏
  • 举报
回复
检查所有页面代码,及时关闭数据库连接

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧