File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes prepared statement  compilation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "prepared statement  compilation." Watch "prepared statement  compilation." New topic

prepared statement compilation.

nandireddy sreekantha reddy

Joined: Dec 05, 2003
Posts: 4
i have used the sql statement in prepared statement like this
connection.preparestatement("update x set col="+name+" where empno="+emp);
what will happen if you write the prepared statement like this .
is this statement compiled once and pass the values from next time onwords
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

You can invoke the execute methods on the same PreparedStatement object any number of times and the SQL is only compiled once. In your example you would not be able to change the values of name or emp as they would have been compiled into the statement when the PreparedStatement was created. You can create a variable in a statement by using a ?, then using PreparedStatement.setXXX() to change the value between executions. Read more about PreparedStatement in the Java Tutorial

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: prepared statement compilation.
It's not a secret anymore!