Oracle Database access from OpenOffice's Macros

Creating a macro - Writing a Script - Using the API

Oracle Database access from OpenOffice's Macros

Postby henrique » Thu Jan 31, 2008 12:35 pm

Hello

How can I retrieve records from a oracle database table inside OpenOffice's Macros???
henrique
 
Posts: 1
Joined: Thu Jan 31, 2008 12:27 pm

Re: Oracle Database access from OpenOffice's Macros

Postby probe1 » Thu Jan 31, 2008 2:28 pm

just the same way you can get them from any other (OOo's registered) data source:
get a context, connect to data source, create a statement, issue your query, handle result(s):

Code: Select all   Expand viewCollapse view
sSQL = " SELECT * FROM tbl_kunde "

Dim oDBKontext
oDBKontext = CreateUnoService ( "com.sun.star.sdb.DatabaseContext" )

If IsNull( oDBKontext ) Then
   msgbox "kein DB Kontext"
   exit sub
End If

' Datenquelle auswählen
' name of OOo registered data source
oDatenquelle = oDBKontext.getByName( "base_Oracle" )
' Verbindung zur DB herstellen
If Not oDatenquelle.IsPasswordRequired Then
   oVerbindung = oDatenquelle.getConnection( , )
Else
   oInteractionHandler = createUnoService( "com.sun.star.sdb.InteractionHandler" )
   oVerbindung = oDatenquelle.connectWithCompletion( oInteractionHandler )
End If

' Statement erzeugen
oStatement = oVerbindung.createStatement

' Abfrage absetzen
oResultSet = oStatement.executeQuery( sSQL )

while oResultSet.next()
' erste Spalte ausgeben
   sKundenname = oResultSet.getString( 1 )
   msgbox sKundenname
Wend
' DB-Ressourcen wieder freigeben
oResultSet.close()
oStatement.close()
oVerbindung.close()

End Sub
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
probe1
Volunteer
 
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests