liiuliu_007
liiuliu_007
2017-09-23 01:57

java.sql.SQLException: ORA-01006: 绑定变量不存在

  • oracle
  • java

错误显示

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:189)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:242)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:554)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1478)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:677)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2371)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2660)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:457)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:387)
at cn.ntt.Dao.InfoDao.searchInfo(InfoDao.java:91)
at cn.ntt.servlet.InfoServlet.doPost(InfoServlet.java:96)
at cn.ntt.servlet.InfoServlet.doGet(InfoServlet.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at cn.ntt.Util.EncodingFilter.doFilter(EncodingFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

Dao里的代码
public List<Info> searchInfo(String sqlvalue,String subsql,String type,int start,int end){
    List<Info> list = new ArrayList<Info>();
    Connection conn=null;
    PreparedStatement ps=null;
    ResultSet rs =null;
    try {
        conn = JdbcUtil.getConn();
        String sql="SELECT * FROM T_INFO ";
        if(!"".equals(subsql)&&subsql!=null){
            if(subsql.equals("info_content")){
                sql+="WHERE INFO_CONTENT ";
            }else if(subsql.equals("info_phone")){
                sql+="WHERE INFO_PHONE ";
            }else if(subsql.equals("info_email")){
                sql+="WHERE INFO_EMAIL ";
            }else if(subsql.equals("id")){
                sql+="WHERE ID ";
            }else if(subsql.equals("info_title")){
                sql+="WHERE INFO_TITLE ";
            }else if(subsql.equals("info_linkman")){
                sql+="WHERE INFO_LINKMAN ";
            }if(type.equals("all")){
                sql += " = '" + sqlvalue + "'";
            }else if(type.equals("like")){
                sql += "like '%" + sqlvalue + "%' ";
            }
            sql+=" ORDER BY ID DESC";
            sql="SELECT * FROM(SELECT U.*, ROWNUM RN FROM("+sql+")"+ 
                "U WHERE ROWNUM<=?) A WHERE A.RN>=?";
        }
        //编译SQL语句
        ps=conn.prepareStatement(sql);
        ps.setInt(1, end);
        ps.setInt(2,start);
        rs = ps.executeQuery();//结果集,只有遍历时才用
        while(rs.next()){
            Info info =new Info();
            info.setId(rs.getInt("ID"));
            info.setInfo_type(rs.getString("INFO_TYPE"));
            info.setInfo_title(rs.getString("INFO_TITLE"));
            info.setInfo_content(rs.getString("INFO_CONTENT"));
            info.setInfo_phone(rs.getString("INFO_PHONE"));
            info.setInfo_linkman(rs.getString("INFO_LINKMAN"));
            info.setInfo_email(rs.getString("INFO_EMAIL"));
            list.add(info);
        }   
    }catch(SQLException e){
        e.printStackTrace();
    }finally{
        JdbcUtil.closeConn(rs, ps, conn);
    }
    return list;
}

Servlet的代码
    else if("search".equals(flag)){
        //获取left.jsp中关键字查询和条件查询
        String sqlvalue=req.getParameter("sqlvalue");
        String subsql=req.getParameter("subsql");
        String type=req.getParameter("type");
        List<Info> list=infoDao.search(sqlvalue, subsql, type);
        int total=list.size();//总共的条数
        int totalPage=0;//总共的页数
        if(total%5==0){
            totalPage=total/5;
        }else{
            totalPage=total/5+1;
        }
        /*totalPage=total%3==0?total/3:total/3+1;*/
        String cp=req.getParameter("currPage");
        if(cp==null||cp==""){
            cp="1";
        }
        int currPage=Integer.parseInt(cp);
        if(currPage<1){
            currPage=1;
        }else if(currPage>totalPage){
            currPage=totalPage;
        }
        int start=0;//开始的条数
        int end=0;//结束的条数
        start=(currPage-1)*5+1;
        end=currPage*5;
        //存放进searchInfo这个Dao方法里
    List<Info> infolist=infoDao.searchInfo(sqlvalue, subsql, type, start, end);
        req.setAttribute("start", start);
        req.setAttribute("end", end);
        req.setAttribute("currPage", currPage);
        req.setAttribute("totalPage", totalPage);
        req.setAttribute("infolist", infolist);
        req.setAttribute("infolist", infolist);
        req.getRequestDispatcher("pages/show/searchshow.jsp").forward(req, resp);
    }   
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐