天天看点

java结果集关闭报错_请教一个java问题,结果集已关闭? 部分代码如下,请大神帮助?...

publicResultSetQuery(StringsqlStr){Connectionconn=null;Statementst=null;ResultSetrs=null;try{conn=this.getConnection();st=conn.createStatement();System.out.println("SQL:"...

public ResultSet Query(String sqlStr)

{ Connection conn=null;

Statement st=null;

ResultSet rs=null;

try{

conn=this.getConnection();

st=conn.createStatement();

System.out.println("SQL:"+sqlStr);

rs=st.executeQuery(sqlStr);

if(rs!=null){

rs.close();

}

if(st!=null){

st.close();

}

if(conn!=null){

conn.close();

}

}

catch(Exception e)

{

e.printStackTrace();

}

return rs;

}

‘’''

public static void main(String args[]) throws Exception

{

DB db=new DB();

String Str="select * from users";

ResultSet rs=db.Query(Str);

if(rs.next())

{

System.out.println(rs.getString("uname"));

}

}

展开