Statement vs. prepared statement in Java
The statement and prepared statement interfaces in Java enable us to use SQL commands to send and retrieve data.
- Statement is used to call normal SQL queries.
- Prepared statement is used to call parametrized or dynamic SQL queries.
Statement stm = conn.createStatement()
PreparedStatement stm = conn.prepareStatement( String Obj )
- In this interface, only SQL queries without parameters can be passed.
- In this interface, parameters can be passed at a run time.
- This interface is preferred when a SQL command needs to be executed once. It is primarily used for DDL statements like CREATE, ALTER, etc.
- This interface is preferred for SQL commands that need to be executed multiple times.
- The performance of this interface is a bit low.
- This interface performs far better than the normal statement.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved