我在其中一个程序中使用JDBC和SQLite创建了一个表。现在,我试图从数据库中读取特定的值。我正在尝试获取最后的订单号,但出现错误。我把我的代码放在下面。不知道出了什么问题:
try {
String sql = "SELECT ordernumber FROM orderTable ORDERBY ordernumber LIMIT 1 DESC";
Connection connection = DriverManager.getConnection(url);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
System.out.println(rs.getInt("ordernumber"));
} catch (SQLException e) {
System.out.println(e.getMessage());
}
更改
String sql = "SELECT ordernumber FROM orderTable ORDERBY ordernumber LIMIT 1 DESC";
到
String sql = "SELECT ordernumber FROM orderTable ORDER BY ordernumber LIMIT 1 DESC";
也许您可以将SQL更新为正确的语法,然后运行它。
String sql = "SELECT ordernumber FROM orderTable ORDERBY ordernumber LIMIT 1 DESC";
(右一个):
String sql = "SELECT ordernumber FROM orderTable ORDER BY ordernumber DESC LIMIT 1 ";