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 SearchDomino.com:
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   
= "com.ibm.as400.access.AS400JDBCDriver";
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
Class.forName(_drv);
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"
+ " KAUKTE, KCULTE, CRACNB,  CREFDT, H6LOTX"
+ " FROM"
+ " FCCRCPP"
+ " WHERE"
+ " JOBNUMBER = "+ jobnumber;
       
// Get a statement from the connection
stmt = con.prepareStatement( sql );
rs = stmt.executeQuery( );
       
while (rs.next()) {
//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) {
e.printStackTrace();
}
 }
 

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
            statement.registerOutParameter
(1, java.sql.Types.CHAR); // error code is 
7 char and is blank if okay
            statement.registerOutParameter
(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 );

            statement.executeUpdate();

            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) {
           System.err.println(sqle.getMessage());
            
        } 
   return jobNumber;
    }
    
  
   
 
}

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

This tip was submitted to the SearchDomino.com 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.

This was first published in January 2008

Dig deeper on Java for Lotus Notes Domino

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close