aspose file tools*
The moose likes JDBC and the fly likes executeUpdate() not inserting record Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executeUpdate() not inserting record" Watch "executeUpdate() not inserting record" New topic
Author

executeUpdate() not inserting record

suresh pillai
Greenhorn

Joined: Oct 30, 2003
Posts: 23
Hi all,
Iam using 'executeUpdate()' to perform two queries.
The first sql statement deleted the records and is performing correctly.
The second sql statement is updating the table. When I check the returned int value, it is '1'.Which is correct as Iam inserting one record into the table.
But when I check the table I do not find any values. It is empty. It is not throwing any sqlException.
Can any one explain?
thanks in advance,
suresh
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Can we see your code?


Dave
suresh pillai
Greenhorn

Joined: Oct 30, 2003
Posts: 23
Hi dave ,
Here is the code :-
//----------------------------------------------------------------
con = DriverManager.getConnection(
"jdbc racle:thin:@"
+ myProp.getProperty("oracle_server","server:1221:IIBR")
, myProp.getProperty("oracle_user","usr")
, myProp.getProperty("oracle_pw","pass"));
stmt = con.createStatement();
// delete prior attempts
ri2=stmt.executeUpdate("DELETE FROM AMDB.WOPAC_PID_PATRON_KEYS "
+ "WHERE PATRON_KEY = '" + patronKey + "' ");
con.setAutoCommit(false);
ri = stmt.executeUpdate("INSERT INTO AMDB.WOPAC_PID_PATRON_KEYS "
"( PID, PATRON_KEY) " + "VALUES " + "(" + sPID + ", '" + patronKey + "')");
con.commit();
// for validation
if (ri == 0) {
//Throw error
} // if (ri == 0)
else {
//Redirect
} // else
stmt.close();
con.close();
//------------------------------------------------------
Note :- It deletes the records. ie the records get removed from the table.
But in case of insert it inserts the record(ie. returns ri=1), but the table does not get updated.
Iam catching both SQLException and exception.
hope that helps.
thanks,
suresh
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Suresh
the only thing I see that might be a problem in your code is in this line:
ri = stmt.executeUpdate("INSERT INTO AMDB.WOPAC_PID_PATRON_KEYS "
"( PID, PATRON_KEY) " + "VALUES " + "(" + sPID + ", '" + patronKey + "')");
It looks like your missing a + after the " at the end of the 1st line, although that might have happened when you posted the code and might not be an issue in your program. Otherwise it looks ok, you might want to try doing it with out turning off auto commit and see if that makes a difference.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: executeUpdate() not inserting record