我正在尝试将Oracle数据导入OfficeBase数据库(FireBird(。我的目标是打开一个像这样直接连接到oracle的记录:
- 使用正确的连接字符串连接到oracle数据库
- 使用适当的SQL获取数据
- 使用循环循环浏览记录
感谢大家的帮助。
我想我已经找到了答案:
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