Get data from DB2 via LotusScript

I have recently made an Lotus Notes Database, where i needed to get some information from DB2.
I this case i also had the issue that only the server could connect to the DB2.

I made an agent that call another agent with the runOnServer method.
Then you can select a document, start a agent that calls a agent on a server, connect to db2, and update the selected document.

Here is an example on how to call db2 in a agent.

Option Public
Option Explicit
Uselsx “NLSXLC”

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Set agent = session.CurrentAgent
Dim doc As NotesDocument
Dim LC_S As New LCSession
Dim LC_Conn As New LCConnection( “DB2″)
Dim LC_FldLst As New LCFieldList(1)
Dim LC_Field As New LCField( LCTYPE_TEXT, 1)
Dim strLCMsg As String
Dim strLCErrorTxt As String
Dim lLCMsgCode As Long
Dim nStatus As Integer
Dim lCount As Long
Dim strSelectStatement As String
Dim strKundenr As String
Dim lTotal As Long
Dim ngl As String
Dim x As string

‘Get doc
Set doc = db.GetDocumentByID(agent.ParameterDocID)

LC_Conn.Userid = “SETUP_ALIAS_USER”
LC_Conn.Password = “SETUP_ALIAS_PASSWORD”
LC_Conn.Database = “SETUP_ALIAS_DB2″
LC_Conn.Disconnect
LC_S.ClearStatus
LC_Conn.Connect
Print “Connect called”

strSelectStatement = “SELECT * FROM DB.Table”
lCount = LC_Conn.Execute( strSelectStatement, LC_FldLst)
Print “Execute Select Statment called”

If lCount <> 0 Then
lCount = LC_Conn.Fetch( LC_FldLst, 1, 1)
‘Select what you want to get from the select
Set LC_Field = LC_FldLst.GetField( 1)
While ( lCount > 0 ) And ( LC_S.Status = LCSUCCESS )
x = x + LC_Field.text( 0)
lCount = LC_Conn.Fetch( LC_FldLst, 1, 1)
lTotal = lTotal + 1

Wend
End If
LC_Conn.Disconnect
LC_S.ClearStatus
‘ex: write to doc
Call doc.Replaceitemvalue(“field”,x)
Call doc.save(True, False)
End Sub

This entry was posted in Lotus, Tip and tagged , , , , , . Bookmark the permalink.

2 Responses to Get data from DB2 via LotusScript

  1. Consider using DECS in some creative ways. Keeping SQL statements out of your code makes it more readable and less vulnerable to exploits of a mum.

  2. http://www.ibm.com/developerworks/lotus ): LSXDB2 SPR# JDEN6JPHE9 – In some cases, users want the user password field sent to NULL when connecting to DB2 on z/OS. The code was inserting an ASCII space character when the user or password field was null from the agent. This problem has been fixed in 6.5.6 and 7.0.2. Refer to the Upgrade Central site for details on upgrading Notes/Domino.

Comments are closed.