This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prepared statement compilation.

 
nandireddy sreekantha reddy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic