本人新手,请问java 操作sql数据库 数据库连接数持续上升导致死机。怎样释放连接数
本人新手,请问java 操作sql数据库 数据库连接数持续上升导致死机。程序调用ResultSet dbquery怎样释放连接数
谢谢 请帮忙写个释放代码
package dbcon;
import java.sql.*;
import java.net.*;
import java.util.StringTokenizer;
import java.util.*;
import
java.io.IOException;
import java.io.PrintStream;
import java.io.*;
import javax.servlet.http.*;
public class dbcon{
private static String driverstr=" ";
private static String user=" ";
private static String password=" ";
private String databasename=" ";
private static String midname="";
private static String errorbz=" ";
private static String url=" "; //"jdbc:microsoft:sqlserver://10.66.39.134:1433;DatabaseName=test";
ResultSet rs;
String vhostipaddress="";
private HttpSession mysession;
public int dbtest()
{
try{
Connection conn=getConn();
return 1;
}catch(Exception e)
{
System.out.print(e.toString());
return 0;
}
}
public int setSession( HttpSession rq)
{
mysession=rq;
return 1;
}
public int putsession()
{
return 1;
}
public void dbexe(String sqlstr)
{
try{
Connection conn= getConn();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.execute(sqlstr);
errorbz="0";
}catch(Exception e)
{
System.out.println(e.toString());
errorbz="1";
}
}
public String getErrorbz()
{
return errorbz;
}
public ResultSet dbquery(String sqlstr)
{
try{
Connection conn=getConn();
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sqlstr);
}
catch(Exception e){
System.out.println(e.toString());
return null;
}
return rs;
}
public void setDatabasename(String value)
{
System.out.println("before"+databasename);
String ax=value;
String bx=ax.substring(0,6);
String cx=ax.substring(6,11);
int rt=0;
if(driverstr.trim().length()==0)
try {
rt=getxml();
databasename=bx+midname.trim()+cx;
}
catch(Exception e)
{
databasename="";
}
databasename=bx+midname.trim()+cx;
System.out.println("after"+databasename);
//databasename=value;
}
public String getDatabasename()
{
return databasename;<