Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC statements

 
Shivaprakash Shettihalli
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the advantage of using Statement over Prepared Statement, not the reverse please
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unlike a prepared statement, which has to be known ahead of time, a statement can take any string and try to execute it as a SQL statement. This is useful for programs that build SQL statement on the fly or that have to execute accept statements passed to it from other programs or components.

It should go without saying that this can be dangerous thing in certain environments (you originally asked this question in the servlets forum), if your code accepts SQL strings (or pieces of SQL Strings) from untrusted clients.
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Statements are usually faster than PreparedStatements if you cannot reuse PreparedStatements. If you can, it determines on the number of times the PreparedStatement can be reused.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic