insert statement problems{Resolved}
I'm having problems updating a database. I use the prepared statement because I want to call some methods to get the values to return. The program compiles and runs fine, but it doesn't update the database.
Code:
PreparedStatement stmt = databaseConnection.prepareStatement("INSERT INTO Session (Last_Name, First_Name,User_Name, Password, Gender, Email_Address) VALUES(?,?, ?, ?, ?, ?)");
stmt.setString(1, "B");
stmt.setString(2, "C");
stmt.setString(3, "D");
stmt.setString(4, "E");
stmt.setString(5, "F");
stmt.setString(6, "G");
stmt.executeUpdate();
That's how I'm doing it. I made sure everything is the same between the DB and my code, so I don't think that's a problem.
Re: insert statement problems
Oooops. Just forgot to close the connection. Resolved.
Re: insert statement problems{Resolved}
It happens, we look for something sooo complex and tend to forget the loose ends! wot a bummer :'(
Re: insert statement problems{Resolved}
Well actually I think it's a flaw in access that causes it not to register updates unless the connection is closed, but I should have closed it anyway.
Re: insert statement problems{Resolved}
System Error did you do a check to see what was being returned from executeUpdate()? Inserts fall under DML so executeUpdate() should return 1.
executeUpdate should only return 0 if an update statement that affects zero rows is executed or it's a DDL statement that's executed.
Re: insert statement problems{Resolved}
Quote:
Originally Posted by Dilenger4
System Error did you do a check to see what was being returned from executeUpdate()? Inserts fall under DML so executeUpdate() should return 1.
executeUpdate should only return 0 if an update statement that affects zero rows is executed or it's a DDL statement that's executed.
Nah, I had no clue about that. I'm guessing that it actually did do the update, but would only show up after the connection was closed.
Let me test it and see....
Re: insert statement problems{Resolved}
It did return a 1. So it is a flaw in access that it only shows up after the connection is closed, even though the update has already taken place.