Statement : It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once then this interface is preferred over PreparedStatement. Example – //Creating The StatRead more
Statement :
It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once then this interface is preferred over PreparedStatement.
Example –
//Creating The Statement Object
Statement ADI = con.createStatement();
//Executing The Statement
ADI.executeUpdate(“CREATE TABLE STUDENT(ID NUMBER NOT NULL, NAME VARCHAR)”);
PreparedStatement :
It is used when you want to use SQL statements many times. The PreparedStatement interface accepts input parameters at runtime.
Example –
//Creating the PreparedStatement object
PreparedStatement ADI = con.prepareStatement(“update STUDENT set NAME = ? where ID = ?”);
Write a program to differentiate between Statement interface and PreparedStatement interface in JDBC.
Statement : It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once then this interface is preferred over PreparedStatement. Example – //Creating The StatRead more
It is used for accessing your database. Statement interface cannot accept parameters and useful when you are using static SQL statements at runtime. If you want to run SQL query only once then this interface is preferred over PreparedStatement.
Example –
//Creating The Statement Object
Statement ADI = con.createStatement();
//Executing The Statement
ADI.executeUpdate(“CREATE TABLE STUDENT(ID NUMBER NOT NULL, NAME VARCHAR)”);
It is used when you want to use SQL statements many times. The PreparedStatement interface accepts input parameters at runtime.
Example –
//Creating the PreparedStatement object
PreparedStatement ADI = con.prepareStatement(“update STUDENT set NAME = ? where ID = ?”);
//Setting values to place holders
//Assigns “RAM” to first place holder
ADI.setString(1, “RAM”);
//Assigns “512” to second place holder
ADI.setInt(2, 512);
//Executing PreparedStatement
ADI.executeUpdate();
See less