Ads Sponsored By Google :)

Thursday, 11 July 2013

Main Difference between PreparedStatement and Statement in Jdbc with Example |Statement vs Prepared Statement in Java

difference between prepared statement and statement, preparedstatement vs statement,  java statement vs preparedstatement, prepared statement and statement in java, preparedstatement vs statement in jdbc, statement vs preparedstatement in jdbc, statement vs preparedstatement java, main difference between statement and preparedstatement in jdbc, difference between statement and preparedstatement in jdbc with example.

Prepared Statement, Callable Statement

1) Statement Interface transfers numbers, Strings, dates etc.. between Java Application and Database, But Large Objects cannot be Transferred by Statement interface1) PreparedStatement transfers numbers, String, dates and large objects between java application and database.
2) Statement Object compiles the sql query, before it is going to tranfer the query to databasse. Even though if the Same query executing multiple times but each time the query is compiled by statement object. So it decreases the performance of an Application.2) PreparedStatement Pre Compiles an Sql statement and that query can be executed from any number of times by rcompilation again. It means PreparedStatement increases the performance of an Application
3) Statement Interface requires Complex sql query to make as dynamic, whenever we want to run the same query for multiple times.3) A Prepared Statement allows to put Parameters (?,?,?) into sql query to make it as dynamic whenever we want to run same query for mutiple number of times, PreparedStatement Performance is bettter than Statement.
Example for the third point why Statement Interface is Complex,why not PreparedStatement.In this Example Insert dat into table.

For Statement Interface :
Stmt.executeupdate(" insert into emp values("+sid+"'"+sname+"'"+marks+")");

For PreparedStatement :
Con.PreparedStatement("insert into emp Values(?,?,?)");
From the above statements Statement Interface dynamic operation with database is quite complex, But PreparedStatement Dynamic Operations is improves th Performance.

Prepared Statement Explanation with Example

Callable Statement Explanation with Example

No comments:

Post a Comment