I've got a problem where I'm inserting data into a database. It's returning that 1 row is being inserted, but when I actually check the database, nothing new has actually been inserted.
Here's my update function:
public int update(String sqlStatement) {
int rows = 0;
try {
Statement st = this.conn.createStatement();
rows = st.executeUpdate(sqlStatement);
this.conn.commit();
st.close();
} catch (Exception err) {
System.out.println("Got err doing update: " + err.getMessage());
}
return rows;
}
And here's the function calling it via it's object:
db = new Database();
int rows = 0;
String sql = "INSERT INTO tblStudent (firstName, lastName, username, password, isAdmin) ";
sql += String.format("VALUES ('%s', '%s', '%s', '%s', %d)", fName, lName, username, passwd, isAdmin);
System.out.println("Trying " + sql);
if((rows = db.update(sql)) == 0) {
System.out.println("Could not create new user");
throw new Exception();
}
System.out.println("Rows " + rows);
As I said, it's reporting that a single row is inserted into the DB, but nothing is actually there. The DB is a MS Access DB.
Any help appreciated.
G