Statement Prepared Statement Callable Statement

Statement, Prepared Statement, Callable Statement -

Statement – 
Statement is the java interfaces under java.sql package. This object is used for executing the SQL Query with the execute methods.
    There the three manner to execute the queries.
1)execute() - execute method are used for execute DML queries.
2)executeBatch() - This method is used for executing many queries at a time. For using this method first add the queries in addBatch() method.
3)executeQuery() - This method is used for select the data from database. This method return ResultSet of database.
4)executeUpdate() - This method is used for update records with in the database.

Prepared Statement –
    Prepared Statement is used for executing the queries with parameter. Any query is compiled and stored in PreparedStatement object at first time.
     PreparedStatement is used for a situation where you want to execute one query with in a loop.

    PreparedStatement pstmt = con.prepareStatement("SELECT NAME FROM STUDENT WHERE name= ?");
   pstmt.setString(1, “Rohan”);
   
Callable Statement -
CallableStatement object is used for call the stored procedure of database.
CallableStatement cstmt = null;
try {
   String SQLQuery = "{call getStdSubject(?, ?)}";
   cstmt = conn.prepareCall (SQLQuery);
   //code will come here
}
catch (SQLException e) {
   //code will come here
}
finally {
   //code will come here
}

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example