JAVA JDBC Programming Question:
Download Questions PDF

How can you use PreparedStatement in JDBC?


This special type of statement is derived from the more general class, Statement. If you want to execute a Statement object many times, it will normally reduce execution time to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement ’s SQL statement without having to compile it first.

PreparedStatement updateSales = con.prepareStatement(”UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?”);

Download JDBC Interview Questions And Answers PDF

Previous QuestionNext Question
What are the different types of Statements in JDBC? How to call a Stored Procedure from JDBC?