【发布时间】:2017-09-20 05:23:15
【问题描述】:
我正在尝试根据 currentQuestion 整数检索字符串值。但是,我在文档中读到 ROW_NUMBER 不能在 Java Derby 的 WHERE 子句中使用。是否有任何其他功能可以让我根据行号过滤结果?到目前为止,我已经写了这个,虽然我在 getQuestion 字符串上遇到了错误。
public String getQuestion(int currentQuestion) throws SQLException {
Statement statement = connection.createStatement();
String getQuestion = ("SELECT QUESTION FROM GAME_TABLE WHERE ROW_NUMBER = ?");
PreparedStatement preStatement = connection.prepareStatement(getQuestion);
preStatement.setString(1, Integer.toString(currentQuestion));
ResultSet resultSet = preStatement.executeQuery();
System.out.println("Question " + Integer.toString(currentQuestion) + " retrieved.");
return resultSet.getString(1);
}
【问题讨论】:
-
你得到什么错误?
-
你可以使用
CTE,或者子查询 -
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "=" at line 1, column 50.