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 Statement & PreparedStatement 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 "Statement & PreparedStatement" Watch "Statement & PreparedStatement" New topic

Statement & PreparedStatement

suman deb
Ranch Hand

Joined: Jul 14, 2005
Posts: 54
hi everybody...

under what situation we can't use PreparedStatement,but we have
to use Statement?
Sujith Kanaparthi
Ranch Hand

Joined: Sep 04, 2005
Posts: 45
Hi Suman,

When u want to exceute the same query in loop then the best one to use is PreparedStatement as it will be precompiled.
I would like you to go through this thread to have better clarificationPrepearedStatement Vs Statement

Aniruddha Mukhopadhyay
Ranch Hand

Joined: Nov 15, 2000
Posts: 59
When you need to compile a SQL stored procedure, Statement would be used.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Aniruddha Mukhopadhyay:
When you need to compile a SQL stored procedure, Statement would be used.

Its unlikely you would compile a Stored Procedure from Java code, this will probably be done when the procedure is created. If you need to call a Stored Procedure from Java, you would use a CallableStatement.
[ September 28, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

The main (only? ) reason for using a Statement instead of a PreparedStatement is when the driver doesn't support PreparedStatements.
I agree. Here's the link:
subject: Statement & PreparedStatement
It's not a secret anymore!