• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Differnce between Statement & PreparedStatement

 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I want to know the difference between Statement & PreparedStatement.Is there any performance boost in using PreparedStatemnt for STATIC SQL Queries (e.g. SELECT * FROM EMP)compared to Statement?

Thanks in Advance,
Shriniwas
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The use of a Statement in JDBC should be 100% localized to being used for DDL (ALTER, CREATE, GRANT, etc) as these are the only statement types that cannot accept BIND VARIABLES.

PreparedStatements or CallableStatements should be used for EVERY OTHER type of statement (DML, Queries). As these are the statement types that accept bind variables.

This is a fact, a rule, a law -- use prepared statements EVERYWHERE. Use
STATEMENTS almost no where.


Also read http://faq.javaranch.com/view?PreparedStatement


Shailesh
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrinivas Mujumdar:
Is there any performance boost in using PreparedStatemnt for STATIC SQL Queries (e.g. SELECT * FROM EMP)compared to Statement?

Yes. The PreparedStatement still gets cached.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic