请教关于数据库连接的问题

05-10-14 lxglgh
小弟最近用jsp开发网站了一个网站,放在万网的虚拟主机,主机是linux+mysql,当我的程序运行一段时间后,就出现如下错误提示:

User '****' has exceeded the 'max_connections' resource (current value: 60)

下面是我用来测试的页面:

(当该页面刷新几十次后,就会报错,程序无法正确读取数据,有用过虚拟主机的朋友,请指点,谢谢)

<%@ page import="java.sql.*,java.util.ArrayList"%>

<%@ page contentType="text/html;charset=gb2312"%>

<%

//ArrayList al=null;

Connection conn=null;

Statement stmt=null;

ResultSet resultset1=null;

try

{

//String DBurl = "";

String DBurl = "这里隐藏,连接没问题";

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

conn = DriverManager.getConnection(DBurl);

stmt = conn.createStatement();

}

catch(SQLException sqlexception)

{

System.out.println(sqlexception.toString());

}

String s4 = "SELECT * FROM info";

resultset1 = stmt.executeQuery(s4);

int i=0;

for(; resultset1.next() && i<=100;i++)

{

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<%=resultset1.getString("topic")%>

<br>

<%

}

%>

<%

try

{

resultset1.close();

stmt.close();

conn.close();

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

%>

<body>

</body>

</html>

lxglgh
2005-10-14 14:45

<%@ page import="java.sql.*,java.util.ArrayList"%>

<%@ page contentType="text/html;charset=gb2312"%>

<%

//ArrayList al=null;

Connection conn=null;

Statement stmt=null;

ResultSet resultset1=null;

try

{

//String DBurl = "";

String DBurl = "这里隐藏,连接没问题";

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

conn = DriverManager.getConnection(DBurl);

stmt = conn.createStatement();

}

catch(SQLException sqlexception)

{

System.out.println(sqlexception.toString());

}

String s4 = "SELECT * FROM info";

resultset1 = stmt.executeQuery(s4);

int i=0;

for(; resultset1.next() && i<=100;i++)

{

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<%=resultset1.getString("topic")%>

<br>

<%

}

%>

<%

try

{

resultset1.close();

stmt.close();

conn.close();

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

%>

<body>

</body>

</html>

lxglgh
2005-10-14 14:46
每次运行都回用

resultset1.close();

stmt.close();

conn.close();

回收资源,怎么还会有上述错误呢?

banq
2005-10-17 10:34
连接池达到最大数目,存在内存泄漏等问题。重整你的JDBC代码,或使用Jdon框架试验一下

猜你喜欢