createstatement vs preparestatement

X

[XaToA]

for the select queries (select * from table) what is better for use:
Statement stmt = conection.createStatement();
stmt.executeQuery(sql);

or

PreparedStatement stmt = conection.PrepareStatement(sql);
stmt.execute();

what is better for use in web applications?
can you help me?

for the updates and inserts y use PreparedStatements

thanks
 
S

Shripathi Kamath

for the select queries (select * from table) what is better for use:
Statement stmt = conection.createStatement();
stmt.executeQuery(sql);

or

PreparedStatement stmt = conection.PrepareStatement(sql);
stmt.execute();

what is better for use in web applications?
can you help me?

for the updates and inserts y use PreparedStatements

thanks

It depends on your usage. If you plan of executing your statement
infrequently, you might want to consider the createStatement() approach. If
you plan on executing that statement frequently, and would not want to incur
the repeated cost of creating and compiling the statement, you may be better
off using prepared statements.

Best to benchmark your application in the environment it is expected to be
used, and you will have a better idea.

The performance differences vary based on many factors, but a 10:1 over
1000s of operations (in favor of the prepared statement) in steady state is
not uncommon. For fewer iterations it can get to 2:1 or even 1:3.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top