Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executeUpdate() not inserting record

 
suresh pillai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we see your code?
 
suresh pillai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic