Call Store Procedure Using Java

I need to export data from Lotus Notes to DB2.(using Java Agent and Stored Procedure). I have wrote a Java agent that opens JDBC and communicate with DB2. Communication with DB2 is working. Now, I need to call stored procedure on the DB2 server. Can anyone please point me to the right direction on how to call stored procedure using java? I can’t find any documentation on this, or I might not be looking at the right place. Thanks in advance for your help or suggestions. Below is how I connect to DB2:

import lotus.domino.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

import java.sql.Date;

import java.sql.ResultSet;

public class JavaAgent extends AgentBase {

public void NotesMain() {

 java.sql.Connection connection =null;

	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();

		 connection = getJDBConnection("jdbc:db2://m60.mw.company.com:60023/test", "id","password") ;



		String queryStr = "SELECT ID FROM MW.PROFILE";

			

					Statement stmt = connection.createStatement();

					ResultSet result =stmt.executeQuery(queryStr);

					while (result.next()) {

						System.out.println(result.getString("ID"));

						

					}

					stmt.close();

					returnJDBCConnection(connection);

	} catch(Exception e) {

		e.printStackTrace();

	}finally{

		try{

		 returnJDBCConnection(connection);

		 }catch(Exception jdbce){

			System.err.println("Error closing jdbc connection"); 

		}

	}

}



public java.sql.Connection getJDBConnection(String jdbcURL, String jdbcUser, String jdbcPassword) throws Exception {

	java.sql.Connection con = null;

		try {

			Class.forName("com.ibm.db2.jcc.DB2Driver");





			con =

				DriverManager.getConnection(

					jdbcURL,

					jdbcUser,

					jdbcPassword);

			return con;

		} catch (Exception e) {

			System.err.println("problems connecting to " + jdbcURL + ":");

			System.err.println(e.getMessage());

			if (con != null) {

				try {

					con.close();

				} catch (Exception e2) {

					e2.printStackTrace();

				}

			}

			return null;

		} // end catch

	}



public void returnJDBCConnection(java.sql.Connection con)

	throws Exception {

		con.close();

	}

}

Subject: Call Store Procedure Using Java

Check out CallableStatement in the java.sql package (Java 2 Platform SE v1.3.1). Basically you’re looking to set up a CallableStatement object using the procedure name and passing it any parameters that the procedure needs. Something like:

CallableStatement cstmt=connection.prepareCall(“{Procedure_Name(?, ?)}”);

cstmt.setString(1, parameter1);

cstmt.setString(2, parameter2);

ResultSet rs=cstmt.executeQuery();

Pete