Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared Statements

 
Allen Thomas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Would anyone know if MS Access supports PreparedStatements?
Thanks.
 
Ayan Kumar Roy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah !
very much
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2712
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic