This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes Reusing PreparedStatement as Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Reusing PreparedStatement as Statement" Watch "Reusing PreparedStatement as Statement" New topic
Author

Reusing PreparedStatement as Statement

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
With regular statement we can easily reuse the same Statement object to execute a series of unique queries/updates.



It is apparently not the case for PreparedStatement, as the creation requires a SQL String as argument, and there's no API to reset a PreparedStatement instance to a different SQL template.

But, is it possible to keep reusing PreparedStatement as if it as a Statement?

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It seems to me you should be able to write a little test program to see if that code does what you expect it to do. Why not try that?
Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
True. Thanks. It doesn't work. The PreparedStatement cannot be reused as general Statement.

In oracle the following error is caused on subsequent execute:
ORA-01006: bind variable does not exist
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reusing PreparedStatement as Statement