This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Prepared Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Prepared Statements" Watch "Prepared Statements" New topic
Author

Prepared Statements

Allen Thomas
Greenhorn

Joined: Jul 02, 2002
Posts: 29
Hi everyone,
Would anyone know if MS Access supports PreparedStatements?
Thanks.
Ayan Kumar Roy
Greenhorn

Joined: Aug 21, 2002
Posts: 10
yeah !
very much


Ayan Kumar Roy.<br />India
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Actually PreparedStatements are supported or not supported by the JDBC Driver... not the database.
Allen Thomas
Greenhorn

Joined: Jul 02, 2002
Posts: 29
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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Jul 02, 2002
Posts: 29
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prepared Statements