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:
- Parameterized query: Provides the facility of parameterized query.
- Reusable: PreparedStatement can be easily used with new parameters.
- Performance: It increases the performance because of database statement caching.
Difference between Statement and PreparedStatement in jdbc:
Statement | PreparedStatement |
|
|
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.