大家好,我是用jdbc连接sql2000的数据库,并用tomcat做连接池,现发现sqlservr.exe和tomcat.exe会不断增大.具体是每天只有几人人登录这个用jsp做的网站,但是一个月下来sqlservr.exe增大了100M,本来在30M,现在变成了100M了,tomcat也变成50M了.这样下去,如果登录的用户到1000个的话,那不是要隔一段时间重启,不知是什么原因.我写的程序大多像下面这样写的:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*,java.sql.*,java.net.*" %>
<%@ page import="javax.naming.*"%>
<%@ page import="javax.sql.*"%>
<%
Context ctx=null;
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
String sql="";
try
{
ctx=new InitialContext();
if(ctx==null)
throw new Exception("没有匹配的环境");
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sql2000");
if(ds==null)
throw new Exception("没有匹配数据库");
conn=ds.getConnection();
sql="select * from users";
statement=conn.createStatement();
rs=statement.executeQuery(sql);
if (rs.next())
{
//做一些东西
%><%=rs.getString("name")%>
<%
}
else
{
//做一些
}
rs.close();
rs=null;
statement.close();
statement=null;
%>
<% //释放数据库连结
if (rs!=null)
{rs.close();
rs=null;
}
if(statement!=null)
{statement.close();
statement=null;
}
if(conn!=null)
{conn.close();
conn=null;
}
if(ctx!=null)
{
ctx.close();
ctx=null;
}
}catch (Exception e)
{
out.println(e.getMessage());
}
finally
{
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (statement!= null) {
try { statement.close(); } catch (SQLException e) { ; }
statement = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) {; }
conn = null;
}
if (ctx != null) {
try { ctx.close(); } catch (Exception e) {; }
ctx = null;
}
}
%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*,java.sql.*,java.net.*" %>
<%@ page import="javax.naming.*"%>
<%@ page import="javax.sql.*"%>
<%
Context ctx=null;
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
String sql="";
try
{
ctx=new InitialContext();
if(ctx==null)
throw new Exception("没有匹配的环境");
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sql2000");
if(ds==null)
throw new Exception("没有匹配数据库");
conn=ds.getConnection();
sql="select * from users";
statement=conn.createStatement();
rs=statement.executeQuery(sql);
if (rs.next())
{
//做一些东西
%><%=rs.getString("name")%>
<%
}
else
{
//做一些
}
rs.close();
rs=null;
statement.close();
statement=null;
%>
<% //释放数据库连结
if (rs!=null)
{rs.close();
rs=null;
}
if(statement!=null)
{statement.close();
statement=null;
}
if(conn!=null)
{conn.close();
conn=null;
}
if(ctx!=null)
{
ctx.close();
ctx=null;
}
}catch (Exception e)
{
out.println(e.getMessage());
}
finally
{
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (statement!= null) {
try { statement.close(); } catch (SQLException e) { ; }
statement = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) {; }
conn = null;
}
if (ctx != null) {
try { ctx.close(); } catch (Exception e) {; }
ctx = null;
}
}
%>
解决方案 »
- JSP <%= %> 语法问题
- jsp后台向页面传值
- uml的问题?????????????????????????????????
- java/JSP中文乱码问题?
- finereport制作详细过程(附件为图)
- JAVA中用URL 类得到文件名的问题
- 怎么把一个结果集写入到一个excel文件下载到客户端??急!!!谢谢!
- 一个有挑战的问题,快来夺分!!
- Jsp中在sybase数据库中用中文做条件查询有问题,在线求教!
- 如果在 Jsp 中数据库操作部分从外部Java文件中引入 ? 怎么作 ?
- 求教:各位大虾 请问这个JSP页面的功能如何实现啊,最好能给些代码? 万分感谢
- 请高手指点迷经。。。。。
即使你有2G的内存也会被慢慢的吃光。。呵呵~~
不要害怕。