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:
JDBC PreparedStatement examples: