• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

executeUpdate() not inserting record

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we see your code?
 
suresh pillai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic