Sample: Query a Domino or DB2 Database

Objectives
The objectives of this sample are:

Time Required
Allow 30 minutes to create and run this sample.

Before You Begin
To build and run this sample you need:

Follow the steps in the Domino Samples Overview to prepare for the sample.  If you want to use the AgentRunner you also have to follow the steps in Setting Up For the AgentRunner.

Preparation for DB2

To set your DB2 userid and password in the source code:

  1. Expand the IBM Domino Examples project.
  2. Expand the com.ibm.ivj.examples.domino.mailagent package.
  3. Expand the MailAgent class
  4. Select the processDB2(String) method.
  5. Find the line connectObject = DriverManager.getConnection(url, "USERID", "PASSWORD");
  6. Change the parameters "USERID" and "PASSWORD" to the userid and password with which you connect to DB2.

To set your classpath:

  1. Select the MailAgent class with mouse button 2.
  2. Select Properties.  The Properties for UppercaseDeptname window will open.
  3. Select the Class Path tab.
  4. Select the Project path checkbox and click Edit.
  5. Select the DB2 class library project.  Click OK.
  6. Click OK to close the Properties window.

Description
This sample shows a Lotus Notes agent that runs automatically when new mail arrives. It checks the incoming mail to see if it is a special mail request that matches a certain format.  If so, the mail is read and a database query is run. The results of the query are send back to the original sender of the mail message.

To setup Notes to run the agent, do the following:

  1. Open your mail database.
  2. From the Create menu, select Agent.
  3. Enter a name for the agent, such as CheckMail
  4. From the When should this agent  run dropdown list, select if new mail has arrived.
  5. Select the java radio button for what should this agent run.
  6. Click the import class files button.
  7. Locate the AgentQuery.class file, click Add.
  8. Click OK.
  9. Press the Esc key to close the Create Agent window. You will be asked if you want to save the agent.
  10. Click Yes.

Running the Agent
To query your Notes database, send yourself a mail message with DBQUERY as the subject and

DATABASE: NOTES DeptDesc.nsf
QUERY: SELECT Deptno,Deptname WHERE Deptno='E11'

as the body of the message.

To query your DB2 database, send yourself a mail message with DBQUERY as the subject and

DATABASE: DB2 JDBC:DB2:SAMPLE

QUERY: Select * from Employee 

as the body of the message.

The results of the query will be sent to you as a mail message.