Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-11-2008, 09:47 AM
Moderator
 
Join Date: Nov 2007
Posts: 1,637
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Callling stored procedures with input/output parameters and ResultSet
Following example shows how to call stored procedures with input parameters, output parameters and ResultSet.

Code:
public static int storedProcWithResultSet (String parms) throws Exception // Stored procedure to be called. CallableStatement cs = conn.prepareCall ("{? = call mypackage.p_astoreproc (?,?,?,?,?,?,?)}"); // register input parameters cs.setString(2, ""); cs.setString(3, ""); cs.setString(4, parms); // regsiter ouput parameters cs.registerOutParameter(5, java.sql.Types.CHAR); cs.registerOutParameter(6, java.sql.Types.CHAR); cs.registerOutParameter(7, java.sql.Types.CHAR); // Procedure execution ResultSet rs = cs.executeQuery(); // Note that you need to retrieve the ResultSet _before_ retrieving // OUTPUT parameters. if ( rs == null) System.out.println( "No resultSet!"); else { // To retrieve columns info. ResultSetMetaData rsmd = rs.getMetaData(); int nbCol = rsmd.getColumnCount(); int i = 0; int j = 1; Vector vResSet = new Vector(); while (rs.next ()) { System.out.println( "Record " + (i+1)); // putting the ResultSet columns in a vector for ( j = 1; j <= nbCol ; j++){ vResSet.insertElementAt(rs.getString(j), 0); vResSet.addElement(rs.getString(j)); } // Reading vector to print ResultSet data for ( int k = 0 ; k < nbColonnes ; k++ ) { if ( vResSet.elementAt(k) != null) System.out.println( vResSet.elementAt(k).toString()); else System.out.println( "Column " + (k+1) + " Null"); } i++; } } // Retrieving Strored Procedure OUTPUT parameters System.out.println( "return code of Stored procedure = : " + cs.getInt(1)); // Retrieving OUTPUT parameters for ( int i = 5 ; i <= 7; i ++) System.out.println( "parameter " + i + " : " + cs.getString(i)); return cs.getInt(1); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing stored procedures mew Database 3 08-20-2008 06:47 PM
Stored Procedures geeta_ravikanti Database 1 04-22-2008 03:34 AM
Calling stored procedures JavaForums Java Blogs 0 12-24-2007 01:30 PM
Stored Procedures with java Albert Database 4 06-08-2007 06:59 AM
stored procedures in Hibernate Alan Database 2 05-31-2007 05:49 PM


All times are GMT +3. The time now is 04:16 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org