Manage Learn to apply best practices and optimize your operations.

How to execute a stored procedure in Lotus Notes Domino using Java

Discover an example stored procedure for Lotus Notes Domino written in Java that returns a Job Number value, which is then used in an executed SQL statement.

Related resources from
Expert Advice: Two stored procedure events not working with DECS and SQL Server back-end

FAQ: Java for Lotus Notes Domino

Reference Center: Java for Lotus Notes Domino

Using stored procedures in Lotus Notes Domino offers a safe, portable and reliable way to build application-to-application interfaces.

As an example of what you can do with stored procedures in Lotus Notes Domino, the Java code below executes a stored procedure that returns a Job Number value. The Job Number value is then used in an executed SQL statement.

import lotus.domino.*;
import java.sql.*;          // JDBC classes
import java.util.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.util.Date;

public class JavaAgent  extends AgentBase {
private static String _url   
= "jdbc:as400://fully.qualified.server:db2portid/dbname";
private static String dbuser   
= "user";
private static String dbpwd   
= "pwd";
private static String _drv   
= "";
private java.sql.ResultSet rs;

public void NotesMain()  {
Vector vec = new Vector();
String [] recordKeyArrs = 
new String [10];
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// (Your code goes here) 
Session s = NotesFactory.createSession();
Database db = agentContext.getCurrentDatabase();
// Get connection to the database
Properties p = new Properties();
p.put("user", dbuser);
p.put("password", dbpwd);
System.out.println("Establish Connection url-" + _url );
Connection con = DriverManager.getConnection(_url, p);
PreparedStatement stmt = null;
String sql;
String userId = "";
Vector custListV= returnCustomerConfigList (s,db);
int j;
for ( j=0;j%lt;custListV.size();j++ ) {
String customerNo = (String) custListV.elementAt(j);
String suffix = "000";
//call to stored procedure  
String jobnumber = loadPMCurrencyRecords
(con, customerNo, suffix) ;
System.out.println("Job Number : " +  jobnumber );
if ( !jobnumber.equals( "" ) ){ //only execute 
if we have a job number
sql = "SELECT"
+ " FROM"
+ " WHERE"
+ " JOBNUMBER = "+ jobnumber;
// Get a statement from the connection
stmt = con.prepareStatement( sql );
rs = stmt.executeQuery( );
while ( {
//loop and create documents
String cC = rs.getString("KAUKTE");
String cL = rs.getString("KCULTE");
String rN = rs.getString("CRACNB");
String tD = rs.getString("CREFDT");
String pD = rs.getString("H6LOTX");
System.out.println(cC + cL );

} //only execute if we have a job number
   } //
if (con != null) con.close();
} catch(Exception e) {

public String loadPMCurrencyRecords
(Connection con, String customerNo, String suffix ) {
CallableStatement statement = null;
String jobNumber = "" ;

try {
statement = con.prepareCall
("CALL cayr9xjh_qp (?,?,?,?,?)");
            // Register the output parameters
(1, java.sql.Types.CHAR); // error code is 
7 char and is blank if okay
(5, java.sql.Types.CHAR); // returns job 
number require for sql 

            // Call the stored procedure
            statement.setString(2, userId);
            statement.setString(3, customerNo );
            statement.setString(4, suffix );


            String returnCode = statement.getString(1);
          /*  if (returnCode != null && 
!returnCode.matches("^\s+$")) {
                throw new DaoException
("Operation was unsuccessful: " + returnCode);
            jobNumber = statement.getString(5); 
            //if (con  != null) con .close();
        } catch (Exception sqle) {
   return jobNumber;

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Anthony Beckford. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on Java for Lotus Notes Domino

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...