Types of statements in JDBC | Java @ Desk
Home » » Types of statements in JDBC

Types of statements in JDBC

Three types of statements in JDBC:

1. Statement(Click for implementation)
2. Prepared Statement(Click for implementation)
3. Callable Statement

SQL query execution involves :

1) Parsing of SQL query string
2) Compilation
3) Execute the SQL query

Statement(Click for implementation) : For each and every incoming SQL query, statement will follow all the three steps. It compiles the SQL query for every request. Hence it is time consuming process. Statement doesn’t offer support for the parameterized SQL queries

Prepared Statement(Click for implementation) : Prepared statement is an optimized version of statement. For the first request, it follows all the steps mentioned above. But if it recieves the SQL execution of the same query again, it will use the pre compiled version of the query and skips step 1 & 2. Hence it is a time saving process. It does not parse and compiles the query on every request.
Prepared Statement doesn’t offer support for the parameterized SQL queries.
Precompilation of the SQL statement leads to overall faster execution and the ability to reuse the same SQL statement in batches

Callable Statement : Callable statement is use to execute the stored procedures. The registerOutParameter() method is something only applicable to stored procedures since they have parameters with a direction (out, in, or in/out). So, use CallableStatments only when calling a stored procedure on the database


Post a Comment