JDBC executeQuery总是抛出异常

时间:2017-06-20 10:23:16

标签: java mysql jdbc

我使用jdbc.Driver获取连接,然后使用预准备语句从mySQL实例获取表。

由于某种原因,每个preparedStatement.executeQuery();抛出"在结果集开始之前"甚至在我尝试使用resultSet之前就是异常。

以下是主类

的示例代码
  public static void main(String args[]) {
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection mySQLConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/operations", "user", "password");
        PreparedStatement preparedStatement = mySQLConnection.prepareStatement("SELECT * FROM operations.feature_properties LIMIT 0,1000");

       ResultSet resultSet = preparedStatement.executeQuery();
       //Exception is thrown by the previous line without using the result set
        mySQLConnection.close();
    } catch (SQLException | ClassNotFoundException e) {
        e.printStackTrace();
    }
}

调用堆栈是:

java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:720)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2617)
at sqlReader.SQLReader.main(SQLReader.java:23)

非常感谢任何帮助!

0 个答案:

没有答案