首页 > 解决方案 > 在 LibreOffice 中,如何仅使用 Basic 连接到 Oracle 数据库

问题描述

我正在尝试将 Oracle 数据导入我的 OfficeBase 数据库 (FireBird)。我的目标是打开一条直接连接到 oracle 的记录,如下所示:

  1. 使用正确的连接字符串连接到 oracle 数据库
  2. 使用适当的 SQL 获取数据
  3. 使用循环遍历记录

谢谢大家的帮助。

标签: databaseoraclelibreoffice-basiclibreoffice-base

解决方案


我想我找到了答案:

Sub Main
Dim oParms() As New com.sun.star.beans.PropertyValue
    sUser$ = "uid"
    sPass$ = "pwd"
    sURL$ = "jdbc:postgresql://localhost:5432/postgres"
    oManager = CreateUnoService("com.sun.star.sdbc.DriverManager")
    AppendProperty(oParms(), "user", sUser)
    AppendProperty(oParms(), "password", sPass)
    AppendProperty(oParms(), "JavaDriverClass", "org.postgresql.Driver")
    oCon = oManager.getConnectionWithInfo(sURL, oParms())
    oStatement = oCon.CreateStatement()
    sSQL = "select * from table order by id desc"
    oResult = oStatement.executeQuery(sSQL)
    Do While oResult.next()
        s = oResult.getString(3) 
        print s
    Loop
    oCon.close()
End Sub

Sub AppendProperty(oProperties(), sName As String, ByVal oValue)
    AppendToArray(oProperties(), CreateProperty(sName, oValue))
End Sub

Sub AppendToArray(oData(), ByVal x)
    Dim iUB As Integer 'The upper bound of the array.
    Dim iLB As Integer 'The lower bound of the array.
    iUB = UBound(oData()) + 1
    iLB = LBound(oData())
    ReDim Preserve oData(iLB To iUB)
    oData(iUB) = x
End Sub
Function CreateProperty(sName$, oValue) As com.sun.star.beans.PropertyValue
    Dim oProperty As New com.sun.star.beans.PropertyValue
    oProperty.Name = sName
    oProperty.Value = oValue
    CreateProperty() = oProperty
End Function

推荐阅读