Skip to main content

Executing a Stored Procedure

You can also execute stored procedures on Caché. The following method executes the RetrieveByContactType procedure stored in Contact. This procedure accepts a single parameter representing the value of the ContactType property. It returns the value of Name for all Contact instances that have a value for ContactType matching the input parameter. The method iterates through the ResultSet returned by the procedure and displays its values.

public class JDBCExamples {
   public static void printContactByType(String type)
   throws SQLException, ClassNotFoundException{
      Connection conn = JDBCExamples.createConnection();
      CallableStatement cs = conn.prepareCall
      ("{call JavaTutorial.Contact_RetrieveByContactType(?)}");
      ResultSet rs = cs.executeQuery();
      while ({

The method uses the java.sql.Connection prepareCall to create the java.sql.CallableStatement object needed to execute the stored procedure. Again, com.intersys.objects.Database provides a prepareCall method that can also be used to create the java.sql.CallableStatement object.


Stored procedures can be defined as Class Queries within Caché class definitions. To learn more about stored procedures and class queries read Class Queries in Using Caché Objects and Defining and Using Stored Procedures in Using Caché SQL.

FeedbackOpens in a new tab