JdbcCallableStatement

JdbcCallableStatement

-------procedure to create oracle9i database-------------------- CREATE OR REPLACE PROCEDURE EXPERIENCE_PRO(ENO NUMBER,E OUT NUMBER)IS d1 date; d2 date; BEGIN select sysdate into d1 from emp where empno=eno; select sysdate into d2 from dual; e:=(d2-d1)/365; END; --------------------------CallacleStatement program----------------------------------------------- import java.sql.*; import java.util.*; public class CallableTest1{ private Connection con; private CallableStatement cstmt; public void openConnection()throws Exception{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");

  }
  public void callProcedure()throws Exception{
      cstmt=con.prepareCall("{ CALL EXPERIENCE_PRO1(? , ?)}");
     Scanner s=new Scanner(System.in);
  System.out.println("enter employe number");
  int eno=s.nextInt();
      cstmt.setInt(1,eno);
      cstmt.registerOutParameter(2, Types.INTEGER);
      cstmt.execute();
      int x=cstmt.getInt(2);
      System.out.println("exp of empno="+x);
  }
  public void closeConnection()throws Exception{
      cstmt.close();
      con.close();
      System.out.println("connection closed");

} public static void main(String args[])throws Exception { CallableTest1 jt=new CallableTest1(); jt.openConnection(); jt.callProcedure(); jt.closeConnection(); } }

----------------------------------------------at Runtime error is........... F:\Jdbc\09 CallableTest1>javac CallableTest1.java F:\Jdbc\09 CallableTest1>java CallableTest1

Exception in thread "main" java.lang.NullPointerException at CallableTest1.callProcedure(CallableTest1.java:12) at CallableTest1.main(CallableTest1.java:31)

plz find error of above program at Runtime saying NullPointerException

View Answers









Related Tutorials/Questions & Answers:
JdbcCallableStatement

Ads