小编Joh*_*ohn的帖子

sqlite preparedstatement最终确定

我有一个
java.sql.SQLException 错误:准备好的语句已经完成
,当我第二次调用相同的preparedStatement时会发生这种情况.我在一种方法中称呼它.

这是数据库Java类(相关部分)

//create the charge table. (ps is PreparedStatement)
try{
   statement.executeUpdate("CREATE TABLE charge(username TEXT NOT NULL, date DATETIME DEFAULT CURRENT_TIMESTAMP, charge REAL, PRIMARY KEY(username, date));");
} catch (SQLException ex) {
   System.out.println("charge table creation failed. exception" + ex);
}
Run Code Online (Sandbox Code Playgroud)

创建费用的方法:

 public void createCharge(String username, double amount){
    try {
        System.out.println(username + amount);

        ps = connection.prepareStatement("INSERT INTO charge VALUES(?, ?, ?);");
        ps.setString(1, username);
        ps.setDate(2, DateConvert.toSQLDate(Date.valueOf(LocalDate.MIN)));
        ps.setDouble(3, amount);
        ps.executeUpdate();
        ps.clearParameters();

        System.out.println("Complete");

    } catch (SQLException ex) {
        Logger.getLogger(MontsRentalDatabase.class.getName()).log(Level.SEVERE, null, ex);
    }
} …
Run Code Online (Sandbox Code Playgroud)

java sqlite

2
推荐指数
1
解决办法
4730
查看次数

标签 统计

java ×1

sqlite ×1