1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JDBC Tutorials

Q. Calling procedures with Callable Statement ?

Callable Statement is used to call stored procedure .

Step 1:
Write the procedure
CREATE OR REPLACE PROCEDURE getEmpAge
(ID IN NUMBER, AGE OUT NUMBER)

IS
Return_AGE NUMBER;
BEGIN
SELECT AGE INTO Return_AGE FROM EMP WHERE ID:=ID;
Return_AGE;
END;

Step 2:
Java code to execute procedure

public class TestDB {
public static void main(String[] args) {
try {

/** Loading the driver*/

Class.forName("com.oracle.jdbc.Driver");

/** Getting Connection*/
Connection con = DriverManager.getConnection("jdbc:oracle://localhost:3306/test","test","test");

/** Creating CallableStatement*/

CallableStatement call = con.prepareCall("call getEmpAge(?,?)");
     call.setInt(1,24); // setting emp id=24
call.registerOutParameter(2,Types.INTEGER);
call.execute();
System.out.println("Emp Age is "+call.getInt(2));


stmt.close();
con.close();

} catch (Exception e) {

e.printStackTrace();
}
     }
}

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy