qq_53488001 2021-12-09 15:52 采纳率: 33.3%
浏览 925
已结题

实在不知道哪里出现了问题Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.

这是源代码:

package handle.data;
import save.data.Record_Bean;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
public class SearchByCondition extends HttpServlet{
   public void init(ServletConfig config) throws ServletException{
      super.init(config);
   }
   public void service(HttpServletRequest request,
               HttpServletResponse response) throws ServletException,IOException{
      request.setCharacterEncoding("utf-8");
      HttpSession session=request.getSession(true); 
      String searchMess= request.getParameter("searchMess");
      String radioMess= request.getParameter("radio");
      if(searchMess==null||searchMess.length()==0) {
         response.getWriter().print("没有查询信息,无法查询");
         return;
      }
      Connection con=null; 
      String queryCondition="";
      float max=0,min=0;
      if(radioMess.contains("shoes_version")){
        queryCondition =
        "SELECT shoes_version,shoes_name,shoes_made,shoes_price "+
        "FROM shoesForm where shoes_version='"+searchMess+"'";  
      }
      else if(radioMess.contains("shoes_name")) {
         queryCondition =
        "SELECT shoes_version,shoes_name,shoes_made,shoes_price "+
        "FROM shoesForm where shoes_name like '%"+searchMess+"%'";
      }
      else if(radioMess.contains("shoes_price")) {
         String priceMess[] = searchMess.split("[-]+");
         try{
           min = Float.parseFloat(priceMess[0]);
           max = Float.parseFloat(priceMess[1]);
         }
         catch(NumberFormatException exp){
            min = 0;
            max = 0;
         }
         queryCondition =
        "SELECT shoes_version,shoes_name,shoes_made,shoes_price "+
        "FROM shoesForm where shoes_price<="+max+" and shoes_price>="+min;  
      }
      Record_Bean dataBean=null;
      try{ 
         dataBean=(Record_Bean)session.getAttribute("dataBean");
         if(dataBean==null){
            dataBean=new Record_Bean();  //创建bean。
            session.setAttribute("dataBean",dataBean);//是session bean。
         }
      }
      catch(Exception exp){} 
      try{ 
          Context  context = new InitialContext();
          Context  contextNeeded=(Context)context.lookup("java:comp/env");
          DataSource ds=
          (DataSource)contextNeeded.lookup("shoesConn");//获得连接池。
           con= ds.getConnection();//使用连接池中的连接。
         Statement sql=con.createStatement();
          ResultSet rs=sql.executeQuery(queryCondition);
          ResultSetMetaData metaData = rs.getMetaData();
          int columnCount = metaData.getColumnCount(); //得到结果集的列数。
          rs.last();
          int rows=rs.getRow();  //得到记录数。
          String [][] tableRecord=dataBean.getTableRecord();
          tableRecord = new String[rows][columnCount];
          rs.beforeFirst();
          int i=0;
          while(rs.next()){
            for(int k=0;k<columnCount;k++) 
              tableRecord[i][k] = rs.getString(k+1);
              i++; 
          }
          dataBean.setTableRecord(tableRecord); //更新bean。
          con.close(); //连接返回连接池。
          response.sendRedirect("byPageShow.jsp"); //重定向。
     }
     catch(Exception e){
         response.getWriter().print(""+e);
     } 
     finally{
        try{
          con.close();
        }
        catch(Exception ee){}
     } 
   }
}  

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 12月17日
  • 已采纳回答 12月9日
  • 创建了问题 12月9日

悬赏问题

  • ¥15 手机应用的时间可以修改吗
  • ¥15 docker 运行OPEN-webui异常
  • ¥15 麒麟系统如何删除光盘刻录痕迹
  • ¥15 recipe通过gem协议传的是什么
  • ¥15 TS2307: Cannot find module 'cc'.
  • ¥15 100小时学会sap 书上pp章节5.22,标准成本计算逻辑?
  • ¥50 达梦数据库误删日志文件重做DAMENG01.log启动仍然-712错误
  • ¥15 cellranger化学处理类型报错
  • ¥15 用texstudio插入图片出现下面情况,怎么办
  • ¥15 ubantu 用samba挂载windows的共享文件夹,无法挂载二级目录和修改文件