02 November 2012

calling procedure and functon from java code

calling stored procedure :

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


String s;
 String stmt="{call test(?)}";
 System.out.println(stmt);
 CallableStatement cs=con.prepareCall(stmt);
 System.out.println("enter the name of the employee");
 s=br.readLine();
 cs.setString(1,s);
 cs.execute();


calling function:

String stmt="{?=call test_fn(?)}";

String stmt="select test_fn('abc') from dual";
CallableStatement cs=con.prepareCall(stmt);
System.out.println("enter the name of the employee");
s=br.readLine();
cs.registerOutParameter(1,java.sql.Types.INTEGER);
cs.setString(2,s);
cs.execute();


to retrieve value
cs.getInt(1) ,so, in general , cs.get(Type)(index)


also instead of  "java.sql.Types.INTEGER", "oracle.jdbc.driver.OracleTypes.INTEGER" can be used.




Delicious add to del.icio.us saved by 0 users

No comments:

Post a Comment