JDBC Prepared Statement Example
Prepared Statement is different from Statement object, When it is created ,it is represented as SQL statement. The advantage of this statement is SQL statement sent to the DBMS,in which it is compiled. The Prepared Statement is helpful in execute and run a same Statement object many times, thus we normally uses prepared statement to reduces execution time.
Understand with Example
The code illustrates an example from JDBC Prepared Statement Example. The code include a class JDBC PreparedstatementExample,Inside the class we have a try block, that include a main ( ) method. The main method ( ) include the list of steps as follow -
Importing a package Java.sql :Network Interface for communicating between front -end application and database.
Inside the try block we load a driver by calling a class.forName( ),that accept driver class as argument.
DriverManager.getConnection ( ) :This method is used to built a connection between url and database.
( ) : This method is used to execute and run a same
String XXX( ) : If you want to supply values in place of the question mark
placeholders before you can execute a
executeQuery ( ) : This method is used to return record set, The return record set is assigned in a result set. The select statement return you a record set .
next ( ): This method return you the next element in the series.
Finally the println print the Employee Id,First Name in the output.
In case the exception exist in a try block, the catch block caught and handle the exception.JdbcPreparedstatementExample.java