
import java.sql.*;

public class DBProcResult {
  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    new DBProcResult();
  }

  public DBProcResult(){
        String user="dba";
        String password="energy";
        String host = "localhost";
        String dbname = "IndeoCRM";
        String url1 = "jdbc:sapdb://" + host + "/" + dbname + ">?trace=DBProcResult.txt" ;
        long start, end;

        try{
        /*
         * load driver and connect
         */
        Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
        Connection connection = DriverManager.getConnection(url1, user, password);
        Statement  stmt       = connection.createStatement();
        try {
          stmt.executeUpdate("drop dbprocedure DBProcResult");
        }
        catch (SQLException ex) {
          //ignore DBProcNotFound-Exception
        }
        /*create a dbproc*/
        stmt.executeUpdate("CREATE DBPROC DBProcResult (IN COMPANY_ID INT) RETURNS CURSOR AS"
                          +" BEGIN"
                          +" SET $CURSOR = 'MYCURSOR';"
                          +" DECLARE :$CURSOR CURSOR FOR SELECT * FROM SUPERDBA.DUAL  WHERE "
                          +" :COMPANY_ID = :COMPANY_ID;"
                          +" END; ");

        /*commit all changes*/
        connection.commit();

        /*
         * select unicode data
         */
        CallableStatement cstmt = connection.prepareCall("{call DBProcResult (?)}");
        cstmt.setString(1,"1");
        cstmt.execute();
        ResultSet rs= cstmt.getResultSet();
        rs.next();

        /*
         * System.out.println
         */
        System.out.println(rs.getString(1));

        /*release the connection*/
        connection.close();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }

  }
}