Ads Sponsored By Google :)

Friday 19 July 2013

Callable Statement in java Jdbc with Example | Difference between Callable Statement and PreparedStatement and Statement

callable statement, callable statement in java, callable statement jdbc, callable statement example, jdbc callable statement, java callable statement, Callable Statement in Jdbc with Example, Callable Statement in java with Example.


Callable Statement :

1)      Callable Statement is an interface which is extended from the PreparedStatement and CallableStatement having one additional feature when compared with PreparedStatement.

2)      The Additional feature of the CallableStatement is we can execute the sql Commands on the database, but we call procedures and functions of database.

3)      In order to get the reference of an object of CallableStatement we need to call prepareCall() method of Connection interface.
Callable Statement

Syntax :

CallableStatement cstmt=con.preparecall(“sqlCommand”);

CallableStatement cstmt=con.preparecall(“{call procedure(pname)}”);


Example Illustrates the Jdbc Callable Statement

import java.util.*;  // Util package

import java.io.*; // IO Pacakage

import java.sql.*; // it is used for all JDBC Connection.

Class JdbcDemo1{

  public static void main(String args[]) throws Exception{

Class.forName(“Oracle.jdbc.driver.OracelDriver”);

Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:XE”,”scott”,”tiger”);

CallableStatement cstmt=con.prepareCall(“EXP(?,?)”);

Int eno=Integer.parseInt(args[0]);

cstmt.setInt(1,eno);

cstmt.registeroutParameter(2,Type.Integer);

cstmt.execute();

Int k=cstmt.getInt(2);

cstmt.cloase();

con.clsoe();

 }

}

No comments:

Post a Comment

LinkWithin