Using Procedures with INOUT Parameters in JDBC

Hi All

It is very easy in Java to pass and get the data for same procedure parameter(using the same parameter as IN and OUT type). All you need to do is to define the parameter with IN and OUT keywords in Stored procedure.
e.g.
PROCEDURE my_proc_name (
in_type        IN      VARCHAR,
in_type_second   IN OUT   VARCHAR,   — This input parameter will now act like an Output parameter as well

Now in the Java class method, All you have to do is to just to set the input and output parameters. e.g.

cstmt = this.getConnection().prepareCall(“{call pkg.my_proc_name(?,?}”);
cstmt.setString(1, “XYZ”);
cstmt.setString(2, “INPUT”); // Assigning the input
cstmt.registerOutParameter(2, OracleTypes.VARCHAR); // registering the output for same parameter.

cstmt.execute();


Thanks
R Vashi

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