Saturday, March 21, 2015

Difference between Statement, PreparedStatement, CallableStatement in JDBC




Difference between StatementPreparedStatementCallableStatement in JDBC



Statement

PreparedStatement

CallableStatement


Prepared statement is a set of precompiled SQL queries

Callable Statement is used to call a stored procedure

Statement Uses for general-purpose access to your database. Useful when you are using static SQL statements at runtime.

PreparedStatement Uses when you plan to use the SQL statements many times.

CallableStatement  Uses when you want to access database stored procedures.

Creating Statement Object

Creating PreparedStatement Object

CreatingCallableStatement Object

The Statement interface cannot accept parameters.

The PreparedStatement interface accepts input parameters at runtime.

The CallableStatement interface can alsoaccept runtime input parameters.

Statement :- It is used to call a query.

Prepared Statement :- It is also used to call a query but written only once and whenever it is used in the program it is called again.

Callable Statement :- It is a query which is used to call a'STORED PROCEDURE'.

Statement: Used for SingleSql statement.If u want retrive singlesql statment use statement.

PreparedStatment:These are precompiled statement,once u compiled need to compile every time.
preparedStatement psmt=con.prepareStatement("Insert into emp(empno,empname,sal) values(?,?,?);

CallableStatement:To call stored procedure inthe database engine
CallbleStatement cs=con.prepareCall("<calll Storedprocedure"?


Prepared Statement is used to input to the tables dynamically.

Callable Statement is used to call stored procedures


Prepared statment are used for the SQL Query statements

Callable statement are used to call the stored proedures.


Prepare statement is precompiled by the database for faster execution

callable statement isused to execute stored procedure in database


prepared statement is compiled only once and executed many times with different parameters avoiding delay of compilation for every retrival (execution).

Callable statement is used for SQL statements already built inside database (PL/SQL procedures etc.) which are permanently precompiled in database.


Prepared statment is used to execute the SQL query.

CallableStatement is used to StoredProcedures and functions



0 comments:

Post a Comment