Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with PreparedStatement

843854Mar 20 2004 — edited Mar 22 2004
I 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..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2004
Added on Mar 20 2004
20 comments
813 views