大侠们,帮帮我吧!这几天快郁闷死了!
数据操作通用类里有个方法
public ResultSet executeQuery(String sql) throws
SQLException,
ClassNotFoundException {
String strDriver="oracle.jdbc.driver.OracleDriver";
String strConn="jdbc:oracle:thin:@127.0.0.1:1521:test";
String dbUser="system";
String dbPwd="123456";
Connection connSet = null;
ResultSet rsSet=null;
Statement stmtSet=null;
rs=null;
try
{
Class.forName(strDriver);
connSet=DriverManager.getConnection(strConn,dbUser,dbPwd);
stmtSet=connSet.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rsSet=stmtSet.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeQuery:"+ex.getMessage());
stmtSet.close();
stmtSet=null;
rsSet.close();
rsSet=null;
connSet.close();
connSet=null;
}
return rsSet;
}
JSP里调用
String nlTitle="";
String nlId="";
String TempCataStr="";
Fun_DB_WEB dbfun=new Fun_DB_WEB();
rs=dbfun.executeQuery("select new_class_title,new_class_id from news_class where new_class_isdel=0 order by new_class_id");
try{
while (rs.next())
{
nlTitle=rs.getString("new_class_title");
nlId=rs.getString("new_class_id");
TempCataStr = TempCataStr+"<img src='images/left_img/join.gif'><a href=newclass.jsp?RootId="+nlId+">"+nlTitle+"</a><br>";
}
System.err.println("得到栏目:"+nlTitle+"ID:"+nlId+"数据库标题:"+rs.getString("new_class_title"));
}
catch(SQLException ex)
{
System.err.println("获取栏目出错:"+ex);
}
为什么老报 : 获取栏目出错:
java.sql.SQLException: 结果集已耗尽大侠们帮我看看吧,分不够,再加!
------解决方案--------------------while(rs.next()) 退出后,结果集游标已到达末尾,你还调用
rs.getString("new_class_title"),就会发生异常。
------解决方案--------------------System.err.println("得到栏目:"+nlTitle+"ID:"+nlId+"数据库标题:"+rs.getString("new_class_title"));
这一句不对
还有 你没有关闭RS,CONN
也有问题
------解决方案--------------------你最后没有关闭rs呀,你再仔细看看,打开了rs肯定要关闭的呀,不关闭应该会用尽的呀
------解决方案-------------------- while (rs.next())
{
nlTitle=rs.getString("new_class_title");
nlId=rs.getString("new_class_id");
TempCataStr = TempCataStr+" <img src='images/left_img/join.gif'> <a href=newclass.jsp?RootId="+nlId+"> "+nlTitle+" </a> <br> ";
} //位置不对吧??
System.err.println("得到栏目:"+nlTitle+"ID:"+nlId+"数据库标题:"+rs.getString("new_class_title"));
//}是不是应该放在这里呢?,不要两次都取同一个字段,直接用nlTitle就可以了