db2 - 如何通过 LotusScript 从 Lotus Notes Client 连接到 DB2?
问题描述
在 Java 代理中简单地使用 JDBC 驱动程序就可以正常工作。现在我需要从 LotusScript 连接 DB2。有很多这样的文章:http: //www.proudprogrammer.no/web/ppblog.nsf/d6plinks/GANI-9DFMRB https://openntf.org/XSnippets.nsf/snippet.xsp?id=db2-run-从莲花脚本到笔记形式
但他们使用 ODBC 连接或其他方式。无论如何,我看不到可以在我的 LotusScript 代理中定义 DB2 主机和端口的位置。用户将无法在每个工作站上配置 ODBC 连接。我需要一些 Domino 本机方法来连接到 DB2。或者在此示例中我在哪里定义 DB2 主机/IP 和端口: https ://openntf.org/XSnippets.nsf/snippet.xsp?id=db2-run-from-lotusscript-into-notes-form
解决方案
您可以使用 LSXODBC 库,但已弃用,因此您可能不应该这样做。当前支持的方法是使用 LSXLC 库,但请注意,它提供了一种非常以 OO 为中心的方法来发送/使用数据,但它非常快,如果您按设计使用它,可以从一个数据提供者移动数据(比如注释)到另一个(比如 DB2)有点容易。
如果您想坚持使用标准 SQL 字符串,您仍然可以使用 LSXLC 使用 LSConnection 对象的“执行”方法来做到这一点。
就连接而言,您只需要确保在机器上安装了适当的驱动程序,然后在创建新的 LSConnect 对象时使用适当的连接参数(例如,ODBC2 用于 ODBC,DB2 用于 CLI DB2 驱动程序, OLEDB 用于 SQL OLE 驱动程序等)。
如果您坚持使用 ODBC 或 OLEDB,则可以通过代码控制连接字符串。如果您使用 CLI DB2 驱动程序(非常、非常快),您需要在安装了驱动程序的每台机器上配置连接。
所有这些都记录在 Designer 帮助中,但在我看来,它并没有以最佳方式组织。但这一切都在那里。
因此,一些示例代码基本上是从我坐在那里的一些代码中复制而来的,并且没有经过测试:
Option Declare
UseLSX "*lsxlc"
Sub Initialize
Dim LCSession As LCSession
Dim lcRDBMS As LCConnection
dim lcFieldList as new LCFieldList()
dim lcField_FirstName as LCField
dim lcField_LastName as LCField
dim strFirstName as string
dim strLastName as string
dim strConnectionType as string
' Hard-coding this here just for this example
' I think you will either want an ODBC (odbc2) or a CLI DB2 (db2) connection
strConnectionType = "odbc2"
Set lcRDBMS = New LCConnection (strConnectionType)
' Set some standard properties on the LCConnection object
lcRDBMS.Userid="<userid>"
lcRDBMS.Password="<password>"
lcRDBMS.MapByName=True
' Properties and property values that are different
' depending on the connection type
select case strConnectionType
case "odbc2" :
' Use the DSN name as configured in the ODBC Control Panel (if on Windows)
lcRDMBS.Database = "<SYSTEMDSN>"
case "oledb" :
lcRDBMS.Server = "<myserver.company.net>"
lcRDBMS.Provider = "sqloledb"
lcRDBMS.Database = "<my_database_name>"
' Not sure this actually changes anything or is even setting the correct property
' But the intent is to make sure the connection to the server is encrypted
lcRDBMS.INIT_ProviderString = "ENCRYPT=TRUE"
case "db2" :
' I am afraid I have lost the connection properties we used to use
' to form up a DB2 CLI connection so the following is just a best guess
' But if you are not going to be using the advance features of LSX to
' connect to DB2 you might as well just a standard ODBC driver/connection
lcRDBMS.Database = "<connection_name>"
End Select
Call lcRDBMS.Connect()
' This call returns a status code and populate the lcFieldList object with our results
lngQueryStatus = LcRDBMS.Execute("<Select FirstName, LastName from SCHEMA.Table WHERE blah>", lcFieldList)
If lngQueryStatus <> 0 Then
If lcFieldList_Destination.Recordcount > 0 Then
' Get our fields out of the lcFieldList object before going into the loop.
' Much more performant
Set lcField_FirstName = lcFieldList.Lookup("FirstName")
Set lcField_LastName = lcFieldList.Lookup("LastName")
While (lcConn.Fetch(lcFieldList) > 0 )
strFirstName = lcField_FirstName.Text(0)
strLastName = lcField_LastName.Text(0)
' Do something here with values
Wend
End If
End If
End Sub
推荐阅读
- jsf - 在数据表行扩展中输入文本,返回空值 primefaces
- c# - 如何在 AssetDatabase.FindAssets() 中使用正则表达式?
- flutter - 触摸时将小部件放在前面
- swift - 如何更改静态变量的值?
- blazor - 如何使 Blazor 项目在子文件夹中工作?
- flutter - 颤振中的SignalR出现错误无协议
- twincat - 如何在 PLC 上启用 TcRTime 看门狗?
- mongodb - 无法将多个文档推送到集合 (11000)
- arrays - 转换列表
- > 到 Flutter 中的 ArrayList
- autodesk-forge - Autodesk Forge 转换错误 - 提取器代码 1073741819