我在takeOutTbl中更新记录时遇到错误(只有几条记录)。任何帮助将受到高度赞赏。这是更新代码:
fine = overdueDays * 10; //the fine is calculated by multiplying the number of overdue days by the 10
simpleUpdate("update takenOutTbl set Random Calculations = Random Calculations " + fine);
它与此方法相关:
public static void simpleUpdate(String update) throws SQLException {
try {
Connection connection = dc.DatabaseConnection(); //a connection to the database is established
PreparedStatement statement = connection.prepareStatement(update); //the conenction is used to prepare the update statement which was sent to this method
statement.executeUpdate();//the statement is executed
statement.close(); //the prepared statement is closed
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error: the database was not updated. Please try again." );
System.err.print(e.getMessage());
}
}
我收到的错误信息是:
user lacks privilege or object not found: RANDOM
答案 0 :(得分:1)
按如下方式更正您的查询:
"update takenOutTbl set [Random Calculations] = [Random Calculations] + " + fine
由于列名称中的空格,您必须稍微帮助MS Access,并指出Random Calculations
是一列。您可以通过将列名括在括号中来完成此操作。
此外,您的查询最后没有+
,所以我在上面的示例中也添加了这个。