我把java代码发出来大家看看是什么问题 jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=www55rccomSQLserver>>>>jdbc:microsoft:sqlserver://127.0.0.1:www55rccomSQLserver 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的Connection Statement ResultSet统统都没有关掉,查多几次数据库就爆了 源码都在这里,大家看看呢,我怎么会自己编病毒哦楼上是说把jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=www55rccomSQLserver换成这行?jdbc:microsoft:sqlserver://127.0.0.1:www55rccomSQLserver 添加finally{ try { if (set != null) set.close(); } catch (SQLException se) { } try { if (stmt != null) stmt.close(); } catch (SQLException e) { } try { if (conn != null) conn.close(); } catch (SQLException see) { }} 0210(DBoy):你的Connection Statement ResultSet统统都没有关掉,查多几次数据库就爆了请问怎么关,代码怎么添加,我用JSP还是新手 chenxb1980(倾听) 添加finally{这个添加在哪里?我是新手,见谅! 在executeQuery()后面加了,每次检索后都关掉,不过还是用pool的好,这样不用关/开,太费时间 不过还是用pool的好,这样不用关/开,太费时POOL怎么用? 有关数据库类的对象用完都必须close public ResultSet executeQuery(String s) { rs = null; try { conn = DriverManager.getConnection(url, user, password); Statement statement = conn.createStatement(1005, 1008); rs = statement.executeQuery(s); return rs; } catch(SQLException sqlexception) { System.out.print(sqlexception.getMessage()); } finally{ rs.close(); statement.close(); conn.close(); } finally应该是这样加的!如果你用JSP不如学学数据源,找找资料自己先. 顺便问一句,如果statement.close();这句抛出异常,conn.close();能关掉吗? rs.close(); statement.close(); conn.close();关这里 up好像研究研究pool比较适合你 你的代码中间有很多明显的问题,首先,你应该把创建jdbc的错误throw 到外面去处理,因为一旦发生了Exception,这个class的实例就没有必要生成,因为jdbc创建不出来,后面就不用在executeQuery了,如果你继续执行executeQuery,反而还多处来许多错误。public class conn { public conn throws ClassNotFoundException { ... Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); }}另外一个问题出在这里Statement statement = conn.createStatement(1005, 1008);首先,我不明白你为什么要加参数,就算要加,也不应该用数字,这种方式谁看得懂啊?文档里面说:createStatement(int resultSetType, int resultSetConcurrency)你的参数含义是createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);不知道你为什么要用这个参数,因为你设置ResultSet为updatabale,所以才会生成大量临时文件,而且这种方法会大量占用内存,应该尽量避免使用。 另外,你的服务器应用必须要经常,显示地关闭数据库连接,否则,你的数据库服务器会受不了的。public class conn{ String user = null; String password = null; String url = null; Connection conn = null; ResultSet rs = null; Statement stmt = null; public conn() { ... } public ResultSet executeQuery(String sql) { ... } public void close() { if (rs!= null) try{ rs.close(); }catch(Exception e){ //ignore } if (stmt != null) try{ stmt.close(); }catch(Exception e){ //ignore } if (con != null) try{ con.close(); }catch(Exception e){ //ignore } }}然后你的jsp或者bean里面要经常 conn.close(); 今天闲着没事就总结了一下EL表达式,希望对大家有帮助 ★★★【请教网站开发高手】 虚心请教 求个jsp分页的代码! 这个怎么解决 我用struts+hibernate开发,但是出现这样的问题。 ireport设计 servlet无法接收"+"字符是怎么回事 为了更好的释放数据资源,用到了Vector 怎么得不到数据呢?强烈郁闷中!!!!!!!!!!! 请问一下jsp中怎么连acess和mysql? jbuilderx与weblogic8.1的配置问题???急啊? 我建了个JScript基础论坛,欢迎初级用户过来讨论。
楼上是说把
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=www55rccomSQLserver
换成这行?
jdbc:microsoft:sqlserver://127.0.0.1:www55rccomSQLserver
try {
if (set != null)
set.close();
} catch (SQLException se) {
}
try {
if (stmt != null)
stmt.close();
} catch (SQLException e) {
}
try {
if (conn != null)
conn.close();
} catch (SQLException see) {
}
}
你的Connection Statement ResultSet统统都没有关掉,查多几次数据库就爆了请问怎么关,代码怎么添加,我用JSP还是新手
添加finally{这个添加在哪里?
我是新手,见谅!
POOL怎么用?
{
rs = null;
try
{
conn = DriverManager.getConnection(url, user, password);
Statement statement = conn.createStatement(1005, 1008);
rs = statement.executeQuery(s);
return rs;
}
catch(SQLException sqlexception)
{
System.out.print(sqlexception.getMessage());
}
finally{
rs.close();
statement.close();
conn.close();
}
finally应该是这样加的!如果你用JSP不如学学数据源,找找资料自己先.
statement.close();
conn.close();
关这里
好像研究研究pool比较适合你
public class conn {
public conn throws ClassNotFoundException {
...
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
}
另外一个问题出在这里
Statement statement = conn.createStatement(1005, 1008);
首先,我不明白你为什么要加参数,就算要加,也不应该用数字,这种方式谁看得懂啊?
文档里面说:
createStatement(int resultSetType, int resultSetConcurrency)你的参数含义是
createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
不知道你为什么要用这个参数,因为你设置ResultSet为updatabale,所以才会生成大量临时文件,而且这种方法会大量占用内存,应该尽量避免使用。
public class conn
{ String user = null;
String password = null;
String url = null;
Connection conn = null;
ResultSet rs = null; Statement stmt = null; public conn()
{
...
} public ResultSet executeQuery(String sql)
{
...
} public void close()
{
if (rs!= null)
try{
rs.close();
}catch(Exception e){
//ignore
}
if (stmt != null)
try{
stmt.close();
}catch(Exception e){
//ignore
}
if (con != null)
try{
con.close();
}catch(Exception e){
//ignore
}
}
}然后你的jsp或者bean里面要经常 conn.close();