Home > Domino Tips > Developer > Java > How to execute a stored procedure in Lotus Notes Domino using Java
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVA

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


Anthony Beckford
01.29.2008
Rating: -2.71- (out of 5)


Lotus Notes, Domino, Workplace and WebSphere tips and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


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.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Java
Java code shortens strings in a SQL table
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
FAQ: Java for Lotus Notes and Domino
Automatically scan Lotus Notes database document attachments for viruses
Creating PDF documents from Lotus Notes

Java for Lotus Notes Domino
Java code shortens strings in a SQL table
Top 10 Lotus Notes Domino programming and development tips of 2007
How to return an HTML representation of a Lotus Notes rich-text field
Shrink Lotus Notes databases with many attachments
Converting Lotus Notes Domino Web pages to PDF files with a Java agent
Developing Eclipse plug-ins for Lotus Notes and Domino -- 7 tips in 7 minutes
A bevy of Notes/Domino development tips
Converting Web pages to images using Java
Creating Microsoft Word documents from Lotus Notes
Sending and logging faxes from Lotus Notes and Domino

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts