数据操作通用类里有个方法
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: 结果集已耗尽
大侠们帮我看看吧,分不够,再加!
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: 结果集已耗尽
大侠们帮我看看吧,分不够,再加!
解决方案 »
- HtmlUnit求解救
- 一个简单的html frame问题
- javascript问题
- struts下载文件时出错:java.lang.IllegalStateException: Cannot forward after response has been committed
- 短信收发平台原理.100分大赠送
- struts-config抛异常Parsing error processing resource path /WEB-INF/struts-config.xml
- 不同web主机间jsp里边如何传递自写类的对象?
- 请jsp高手看一下response.setHeader的问题(问了一天了,没有人会的),急啊
- 小弟求教,一个奇怪的问题(关于取出数据显示不正确)
- 求把以下java转成php
- 无法注册JDBC驱动程序
- 请教一个图片处理的问题
rs.getString("new_class_title"),就会发生异常。
还有 你没有关闭RS,CONN也有问题
{
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就可以了
{
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就可以了
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+"数据库标题:"+nlTitle;
}
}
catch(SQLException ex) {
System.err.println("获取栏目出错:"+ex);
}
conn连接没有关闭,你Fun_DB_WEB dbfun=new Fun_DB_WEB();
建立一个连接,当然会耗尽结果集了,建议代码写的规范些
如:
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);
}
//增加如下内容,具体的conn以程序中的对应
finally{
try{
if(rs!=null) {
rs.close();
}
if(conn!=null){
conn.close();
}
}
catch (Exception e1) {
e1.printStackTrace();
}
}