CodesJava

Easy learning with example program codes

JDBC PreparedStatement interface


The JDBC PreparedStatement is used to execute parameterized queries against the database. PreparedStatement is an interface which provides the methods to execute parameterized queries. A parameter is represented by ? symbol in JDBC. PreparedStatement extends the Statement interface. We can get a PreparedStatement object by invoking the prepareStatement() method of Connection interface.

Syntax: PreparedStatement pstmt = conn.prepareStatement(SQL);

Advantages of PreparedStatement:

  1. Parameterized query: Provides the facility of parameterized query.
  2. Reusable: PreparedStatement can be easily used with new parameters.
  3. Performance: It increases the performance because of database statement caching.

Difference between Statement and PreparedStatement in jdbc:

Statement PreparedStatement
  1. Statement not executes the parameterized query.
  2. Relational DB uses following 4 step to execute a query:
    a. Parse the query.
    b. Compile the query.
    c. Optimize/Plan the query.
    d. Execute the query.
    A statement always executes the all four steps.
  3. No database statement caching in case of statement.
  1. PreparedStatement can execute the parameterized query.
  2. Relational DB uses following 4 step to execute a query:
    a. Parse the query.
    b. Compile the query.
    c. Optimize/Plan the query.
    d. Execute the query.
    PreparedStatement pre-executes first three steps in the execution.
  3. It provides the database statement caching the execution plans of previously executed statements. Hence database engine can reuse the plans for statements that have been executed previously.

JDBC PreparedStatement examples:

1. JDBC PreparedStatement creates a table example.

2. JDBC PreparedStatement inserts a record example.

3. JDBC PreparedStatement updates a record example.

4. JDBC PreparedStatement select records example.

5. JDBC PreparedStatement deletes a record example.

6. JDBC PreparedStatement batch update example.

 
Next Topic: JDBC PreparedStatement creates a table example.
Previous Topic: JDBC Statement batch update example.

Related Topics:

JDBC PreparedStatement creates a table example.
JDBC PreparedStatement inserts a record example.
JDBC PreparedStatement updates a record example.
JDBC PreparedStatement select records example.
JDBC PreparedStatement deletes a record example.
JDBC PreparedStatement batch update example.

 

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki