السلام عليكــم ورحمـة الله وبركاتــه
عند تنفيذ الكود التالي يظهر لي رساله
SQLException : ResultSet object is closed
فما الحل في هذه الحاله
الكود :
DBConn.java
public class DBConn {
private Connection createConnection()throws DBException{
/*
code to return conn goes here
*/
return conn;
}
public ResultSet executeQuery (String queryText)throws DBException{
ResultSet rs = null;
Connection conn = null;
Statement stmt = null;
try{
conn = createConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery (queryText);
}catch (SQLException ex){
//ex.printStackTrace();
throw new DBException();
}finally{
try{
if ( stmt != null)
stmt.close();
if ( conn != null)
conn.close();
}catch(SQLException ex){
throw new DBException();
}
}
return rs.clone();
}
}كود الفئه Test.java
public class Test {
public static void main (String[] args)throws DBException, SQLException{
DBConn dbconn = new DBConn();
ResultSet rs = dbconn.executeQuery ("SELECT * FROM News");
while ( rs.next()){
System.out.println (rs.getString(1));
}
}
}