Return to site

In JDBC, what are the different types of Statement?

· java,interview,video

JDBC provides three types of statements to interact with the database:
1️⃣ Statement
➡️ Used for simple SQL queries without parameters.
➡️ Suitable for executing static SQL like SELECT * FROM users.
⚠️ Less efficient for repeated queries.

2️⃣ PreparedStatement
➡️ Precompiled SQL statement that accepts parameters.
➡️ More secure (prevents SQL injection) and faster for repeated executions.
🔸 Example: SELECT * FROM users WHERE id = ?

3️⃣ CallableStatement
➡️ Used to call stored procedures in the database.
➡️ Can handle IN, OUT, and INOUT parameters.
🔸 Example: {call getUserDetails(?)}

🧠 Rule of thumb: