Problem with PreparedStatement
843854Mar 20 2004 — edited Mar 22 2004I am trying a simple prepared statement to insert a row.
PreparedStatement pstmt = conn.prepareStatement("insert into nametable (name, location) values (?, ?)");
pstmt.setString(1, "William Wallace");
pstmt.setString(2, "Scotland");
System.out.println("updated rows - " + pstmt.executeUpdate());
When i run this i get "updated rows - 1" which is correct but when i check the DB nothing is there..the intresting part is that if i use a select query after this it works fine and i can see that the row i inserted using prepared statement is there..
query = "select * from nametable";
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData meta = rs.getMetaData();
int numCol = meta.getColumnCount();
int i = 0;
for(i = 1; i <= numCol; i++) {
System.out.print(meta.getColumnName(i) + "\t");
}
System.out.println();
while(rs.next()) {
for(i = 1; i <= numCol; i++) {
System.out.print(rs.getString(i) + "\t");
}
System.out.println();
}
I have done conn.commit() and pstmt.close(), rs.close() after these.
Please let me know what is happening..this is driving me nuts..