Johnatan56
Honorary Master
- Joined
- Aug 23, 2013
- Messages
- 30,955
Hi guys,
I am currently working on a project but can't seem to get past this error.
I am using java to create/manipulate the SQLite database.
This is the class that deals with the database code, here is the creation of the charge table:
And adding a new row:
I declared PreparedStatement ps right at the beginning and Connection connection as well.
In the other class:
db is an instance of the database creation class.
I am getting the exception (EDIT: adding the printout just before, the first createCharge is succesful):
Any help/explanation of what I am doing wrong would be appreciated.
Kind Regards,
J
EDIT:
for the SQL date:
I am currently working on a project but can't seem to get past this error.
I am using java to create/manipulate the SQLite database.
This is the class that deals with the database code, here is the creation of the charge table:
Code:
//create the charge table.
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);
}
Code:
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(); //Line 170
ps.clearParameters();
System.out.println("Complete");
} catch (SQLException ex) {
Logger.getLogger(MontsRentalDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
}
I declared PreparedStatement ps right at the beginning and Connection connection as well.
In the other class:
Code:
public void createRentals(){
//hardcoded for on database creation.
db.createCharge("450", 100.00);
db.createRental("450", 1);
db.createCharge("450", 150.00);
db.createRental("450", 4);
}
I am getting the exception (EDIT: adding the printout just before, the first createCharge is succesful):
Code:
450100.0
Complete
450150.0
SEVERE: null
java.sql.SQLException: The prepared statement has been finalized
at org.sqlite.core.NativeDB.throwex(NativeDB.java:429)
at org.sqlite.core.NativeDB.reset(Native Method)
at org.sqlite.core.DB.executeUpdate(DB.java:878)
at org.sqlite.jdbc3.JDBC3PreparedStatement.executeUpdate(JDBC3PreparedStatement.java:99)
at server.RentalDatabase.createCharge(RentalDatabase.java:170)
Any help/explanation of what I am doing wrong would be appreciated.
Kind Regards,
J
EDIT:
for the SQL date:
Code:
public class DateConvert {
public static java.sql.Date toSQLDate(java.util.Date date){
return new java.sql.Date(date.getTime());
}
public static java.util.Date toJavaDate(java.sql.Date date){
return new java.util.Date(date.getTime());
}
}
Last edited:
