Callablestatement Example in Jdbc


package com.Javastuff.jdbc;


import java.sql.*;
/**
 * @author Javastuff
 */
public class CallableStatementExample {


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

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@mysys:1521:javastuff","scott","tiger");

//Step1: Get CallableStatement
    CallableStatement cs= con.prepareCall("{call createAccount (?,?,?,?,?,?)}");

//Step2: set IN parameters
cs.setInt(1, 101);
cs.setInt(2, 10);
cs.setString(3, "Santosh");
cs.setDouble(4, 10000);
cs.setString(5, "Hyderabad");
cs.setInt(6, 123456789);

//Step3 : register OUT parameters
//In this procedure example we dont have OUT parameters 


//Step4 Execute the CallableStatement
cs.execute();


System.out.println("Account Created");

con.close();
}//main
}//class



Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email