Java 使用Prepared语句为JQuery JTable选择值

Java 使用Prepared语句为JQuery JTable选择值,java,mysql,servlets,prepared-statement,jquery-jtable,Java,Mysql,Servlets,Prepared Statement,Jquery Jtable,我根据Java servlet处理的Jquery JTable的搜索查询字符串选择值。我正在接收筛选器的请求参数以及startPageIndex和recordPageIndex。但是有一个Mysql错误。请查看下面的代码/错误 根据页面选择列 if(filter != null && !filter.trim().equals("")){ query = "SELECT C1, C2, C3, C4, C5" + "FROM D

我根据Java servlet处理的Jquery JTable的搜索查询字符串选择值。我正在接收筛选器的请求参数以及startPageIndex和recordPageIndex。但是有一个Mysql错误。请查看下面的代码/错误

根据页面选择列

  if(filter != null && !filter.trim().equals("")){
        query = "SELECT C1, C2, C3, C4, C5"
                + "FROM DEPARTMENTS "
                + "WHERE  C2= ? OR C3= ? OR C4= ? OR C5= ? "
                + "ORDER BY department ASC  LIMIT "
                + "? ,  ? ";              

        // the last two values used for table pagination

        pStmt = dbConnection.prepareStatement(query);

        pStmt.setString(1, filter.trim());
        pStmt.setString(2, filter.trim());
        pStmt.setString(3, filter.trim());
        pStmt.setString(4, filter.trim());
        pStmt.setInt(5, startPageIndex);
        pStmt.setInt(6, recordsPerPage);

        ResultSet rs = pStmt.executeQuery(query);
        System.out.println("query executed " + query);

          while (rs.next()) {
                   // Stores in List used to populate in Jquery JTable
          }
    }
MySQL错误:

  if(filter != null && !filter.trim().equals("")){
        query = "SELECT C1, C2, C3, C4, C5"
                + "FROM DEPARTMENTS "
                + "WHERE  C2= ? OR C3= ? OR C4= ? OR C5= ? "
                + "ORDER BY department ASC  LIMIT "
                + "? ,  ? ";              

        // the last two values used for table pagination

        pStmt = dbConnection.prepareStatement(query);

        pStmt.setString(1, filter.trim());
        pStmt.setString(2, filter.trim());
        pStmt.setString(3, filter.trim());
        pStmt.setString(4, filter.trim());
        pStmt.setInt(5, startPageIndex);
        pStmt.setInt(6, recordsPerPage);

        ResultSet rs = pStmt.executeQuery(query);
        System.out.println("query executed " + query);

          while (rs.next()) {
                   // Stores in List used to populate in Jquery JTable
          }
    }

您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用接近“”的正确语法?或者C3=?或者C4=?或者C5=?在select子句的第1行,按C3 ASC'订购,在C5之前或之后添加空格:

query = "SELECT C1, C2, C3, C4, C5 "
        + "FROM DEPARTMENTS "
        + "WHERE C2 = ? OR C3 = ? OR C4 = ? OR C5 = ? "
        + "ORDER BY department ASC LIMIT ?, ?";

我认为您的查询没有任何问题,但我发现您的查询与异常之间存在冲突。您的查询表明您的where类是C2=?或者C3=?或者C4=?或者C5=?但是你的例外是说,或C1=有问题吗?或者C2=?或者C3=?按C3 ASC排序是否确实运行相同的查询。@PrasadKhode抱歉编辑了错误部分