• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Prepared Statements

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
Would anyone know if MS Access supports PreparedStatements?
Thanks.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah !
very much
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually PreparedStatements are supported or not supported by the JDBC Driver... not the database.
 
Allen Thomas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Thanks.
Would any of the two or anyone know how to capture the exception when a illegal value is trying to be inserted (using the PreparedStatement executeUpdate() )into a table?
For example:
try{
String murInsertQry = "INSERT INTO table (id, iDdesc, idtype) VALUES (?,?,?)";
PreparedStatement preparedStmt = db.prepareStatement(murInsertQry);
while(!(myVector.isEmpty())){
preparedStmt.setInt(1, id);
preparedStmt.setString(2, idDesc);
preparedStmt.setInt(3, idType);
int test = preparedStmt.executeUpdate();
}
}catch(Exception e){
e.printStackTrace();
}
The problem is that I could process most of my data and insert them in but when I run into a illegal value such as duplicate id's, I get an exception and the program terminates the loop without process the other records. How would I know to capture the exception and still continue through the loop and insert? That is why I created the int test variable but at that point it is too late. Thanks in advance for any suggestions.
Allen
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put a try-catch block inside your while that catches the exception and does whatever error handling you want (logging, etc...) but does not propagate the exception.
 
Allen Thomas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris for your help! It worked. I don't know what I was thinking or not thinking. =)
I'm sorry...what did you mean by "does not propagate the exception"?
Thanks
Allen
[ October 17, 2002: Message edited by: Allen Thomas ]
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic