Tip

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

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.