Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Statement interface

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 507
    Comment on it

    Statement interface:

    It provides methods to interact with database means using Statement interface we can execute SQL queries.The createStatement() is present in java.sql.Connection interface and it does not take any argument.

    To use Statement interface we create object of Statement by calling createStatement() method .

    Syntax:

    Statement stmt=con.createStatement();

     

    Example:

        import java.sql.*;  
        class InsertRecord{  
        public static void main(String args[])throws Exception{  
          
        Class.forName("oracle.jdbc.driver.OracleDriver");  
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");  
        Statement stmt=con.createStatement();  
          
        //stmt.executeUpdate("insert into employee values(13,'Amit',150000)");  
        //int result=stmt.executeUpdate("update employee set name='Ankit',salary=10000 where id=13");  
        int result=stmt.executeUpdate("delete from employee where id=13");  
          
        System.out.println(result+" records affected");  
        con.close();  
        }}  

    Commonly used Methods of Statement Interface:

    1. public ResultSet executeQuery(String sql)  : It execute SELECT query. It returns the object of ResultSet Interface.

    2. public int executeUpdate(String sql): It is used to execute create, drop, insert, update, delete statements .

    3. public boolean execute(String sql): It is used to execute queries that  return multiple results.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: