Statement interface in java

Statement interface

 Used to create statement object & handle the static dynamic queries

Statement interface methods

 It allows us to explicitly close the statement object
 This actually releases all the resources used on database server & JDBC driver statement.close()

 It executes parsed SQL statement against database with the help of JDBC drivers
 It is useful when SQL statement returns multiple result sets. This occurs generally in stored procedure
 The execute() method will return true if the result is ResultSet object & false if result is integer result

 Enables us to execute SQL update statement like delete, insert & update
 It returns an integer which determine how many records are affected

 Enables us to send “select” statement to the database & receive result from database
 It returns a ResultSet object
 Method next() moves ResultSet object to next record
 Initially the record pointer is placed on a blank record preceded to first
 As long as there are records, this method returns true else it returns false
 getUpdateCount(): returns no. of records which are updated

import java.sql.*;
class test
public static void main(String args[])throws Exception
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:xe”,”system”,”system”);
Statement stmt=con.createStatement();
int result=stmt.executeUpdate(“delete from tab where id=1″);

Leave a Reply

Your email address will not be published. Required fields are marked *