| Author |
Differnce between Statement & PreparedStatement
|
Shrinivas Mujumdar
Ranch Hand
Joined: Aug 27, 2004
Posts: 328
|
|
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
Joined: Aug 13, 2004
Posts: 1076
|
|
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
|
Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Differnce between Statement & PreparedStatement
|
|
|