“ java.sql.SQLException”的问题:对空结果集的非法操作

时间:2019-03-16 20:01:28

标签: java jdbc

这是我的servlet的一部分:

                String sql ="SELECT DISTINCT tranzactii.Data_operatiei as d_o, tranzactii.Id_cont_sursa as i_cs, tranzactii.id_cont_destinatie as i_cd,tranzactii.suma_tranzactie as tsum FROM tranzactii "+
                        "where Data_operatiei between ? and ?";
                PreparedStatement psm = connection.prepareStatement(sql);
                psm.setString(1, StartDate);
                psm.setString(2, EndDate);
                ResultSet resultSet = psm.executeQuery();
                System.out.println("extraCont2");
                //resultSet.first();

                while(resultSet!=null){
                    System.out.println("tran");
                    String Data_operatiei = resultSet.getString("d_o");
                    String suma_tranzactie = resultSet.getString("tsum");
                }

    }
}

And the start of Eclipse report is:
java.sql.SQLException: Illegal operation on empty result set.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
    at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:850)
    at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5768)
    at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5688)
    at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5728)
    at banking.web.servlets.extraCont.doPost(extraCont.java:88)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

我尝试过,现在使用resultSet.beforeFirst(),通过删除“?”修改了我的sql select语句。但还是一样。 而且我遵循了一些stackoverflow链接,但没有用。

0 个答案:

没有答案