[Java/J2EE] Launch a stored Oracle procedure with IN and OUT parameters

Öracle:
CREATE OR REPLACE PROCEDURE get_customer_id (p_customer_id OUT NUMBER, p_order_id IN NUMBER)
IS
BEGIN
   SELECT customer_id INTO p_customer_id FROM orders WHERE order_id = p_order_id; 
EXCEPTION
   WHEN OTHERS
   THEN
      RAISE;
END get_customer_id;
/
Java:
DBprofil[] profil = ResAppli.getDatabaseProfiles();
SessionBase mySessionBase = new SessionBase(profil[0].clonage());
String request = “{call get_customer_id(?, ?)}”;
CallableStatement call = mySessionBase.prepareCall(request);
call.registerOutParameter(1, java.sql.Types.INTEGER);
call.setInt(2, myOrder.getId().intValue());
call.execute();
mySessionBase.commit();
System.out.println(“Customer ID is: ” + call.getInt(1));
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: