나는이 클래스를 다른 클래스에서 호출하여 괜찮습니다. 그러나 열려있는 모든 단일 mysql 연결을 닫고 싶습니다. 내가 연결 trought 닫으려고 할 때 문제가 일어나고오류 "ResultSet이 닫힌 후 작업이 허용되지 않습니다."MySQL 연결 종료시
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class BACENGQueryDatabases {
public String Query;
public BACENGQueryDatabases(String Query){
this.Query = Query;
}
public ResultSet LoadQuery() throws Exception{
// Accessing Driver From Jar File
Class.forName("com.mysql.jdbc.Driver");
//Get credentials from Property file
BACENGPropertiesFile user = new BACENGPropertiesFile("user.cred");
BACENGPropertiesFile passwd = new BACENGPropertiesFile("passwd.cred");
BACENGPropertiesFile database = new BACENGPropertiesFile("database.system");
BACENGPropertiesFile DBServer = new BACENGPropertiesFile("DBServer.system");
BACENGPropertiesFile DBPort = new BACENGPropertiesFile("DBPort.system");
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
//DB Connection
con = DriverManager.getConnection("jdbc:mysql://"+DBServer.properties()+":"+DBPort.properties()+"/"+database.properties()+"",""+user.properties()+"",""+passwd.properties()+"");
//DB Connection
String sql =Query;
pst = con.prepareStatement(sql);
//System.out.println(sql); //Just to test
rs=pst.executeQuery();
con.close();
return rs;
}
}
: 다음
con.close();
을, 출력은 다음과 같습니다
이
내 데이터베이스에 연결하기 위해 내 클래스입니다"Operation not allowed after ResultSet closed"
나는 연결을 닫지 못해서 오류가 발생하는 것을 매우 의심 스럽습니다. 연결이 닫히고 (결과 집합을 닫는 문을 닫음) 나중에 결과를 얻고 어쨌든 결과 집합을 사용하려고합니다. – Gimby
그러면 연결을 닫고 결과 세트를 열 수 있습니까? – Sallyerik
@Sallyerik 불가능하지 않습니다. –