在Lotus Notes平台访问关系型数据库,方法主要有以下4种:
1)LS:DO(ODBC):异种平台互访数据库的数据源;
2)DECS:Lotus DECS服务;
3)LC LSX:利用LOTUS CONNECTOR的API访问外部数据库;
4)LEI(LOTUS ENTERPRISE INTERGRATOR):LOTUS的一个工具软件,用来在不同的数据平台上交换数据。
本文将对对利用LS:DO(ODBC)技术实现Notes访问DB2/400数据库进行介绍。
本文将以近期公司实施的海关EDI加贸企业联网监管系统的Notes端开发片段进行阐述。
1、 Notes端创建对应AS/400端需要访问数据的PF文件(ZICTLP)的DDS结构的表单,其中域栏表示Notes端的字段,FIELD ID栏是DDS定义的字段:
2、表单创建完毕,接着创建对应的View,添加『更新参数表』按钮:
☆『更新参数表』按钮后台对应的LotusScript语言如下:
Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim session As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim FullFileName As String Set db = session.CurrentDatabase Dim view As NotesView Dim collection As NotesViewEntryCollection Dim entry As NotesViewEntry Set view = db.GetView("EDI参数表") Set collection = view.AllEntries Set entry = collection.GetFirstEntry() While Not(entry Is Nothing) Set doc = entry.Document doc.Remove(True) Set entry = collection.GetNextEntry(entry) Wend Call ws.ViewRefresh 'Create Connection object Set Con = New ODBCConnection 'Connect to data source 'R21AFLB1' Dim ds As String, user As String, pw As String ds = "R21AFLB1" user = "RINKS211" pw = "RINKS211" retcode% = Con.ConnectTo( ds, user, pw ) 'Exit if Connection failed If ( retcode% = False ) Then Msgbox "不能正常连接数据源:" + ds error% = conn.GetError extendedMessage$ = conn.GetExtendedErrorMessage(error%) Msgbox extendedMessage$ Exit Sub End If 'Create Query object Set Qry = New ODBCQuery 'Assign Connection to Query Set Qry.Connection = Con 'Assign SQL Query Qry.SQL = " Select * from ZICTLP where CTLTAG='I' " 'Create ResultSet Object Set Res = New ODBCResultSet 'Assign Query to ResultSet Set Res.Query = Qry 'Execute Query retcode% = Res.Execute 'Exit if Execute failed If ( retcode% = False ) Then Msgbox "不能执行查询:" + Qry.SQL error% = data.GetError extendedMessage$ = data.GetExtendedErrorMessage(error%) Msgbox extendedMessage$ Exit Sub End If 'If No ResultSet then Exit sub If Not Res.IsResultSetAvailable() Then Msgbox "没有找到记录!" Exit Sub End If Do Res.NextRow Set doc = db.CreateDocument doc.Form = "ZICTLP" 'Transfer data from zictlp doc.XCTLITM = Res.GetValue("CTLITM") doc.XCTLNO = Res.GetValue("CTLNO") doc.XCTLHS = Res.GetValue("CTLHS") doc.XCTLHSB = Res.GetValue("CTLHSB") doc.XCTLCML = Res.GetValue("CTLCML") doc.XCTLEML = Res.GetValue("CTLEML") doc.XCTLCUR = Res.GetValue("CTLCUR") doc.XCTLTAG = Res.GetValue("CTLTAG") doc.XCTLDAT = Res.GetValue("CTLDAT") doc.XCTLFT1 = Res.GetValue("CTLFT1") Call doc.Save(False,False) Loop Until Res.IsEndOfData Call ws.ViewRefresh con.Disconnect End Sub |
3、Notes客户端配置R21AFLB1为数据源名称的ODBC。
控制面板—管理工具—数据源(ODBC)—系统DSN,添加“Client Aclearcase/" target="_blank" >ccess ODBC Driver (32-bit)”驱动程序。
在“常规”栏中添加“数据源名:R21AFLB1”。
在“服务器”栏中指定“SQL缺省库:R21AFLB1”,出于数据安全,“连接类型”指定为“只读(只允许Select语句)”。
为避免出现转换数据时的不必要麻烦,建议在“转换”栏把“将二进制数据(CCSID 65535)转换为文本”选项选上。
4、需要实现数据从DB2/400—>Notes时,只需要执行『更新参数表』按钮即可。