Oracle Database access from OpenOffice's Macros

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
henrique
Posts: 1
Joined: Thu Jan 31, 2008 12:27 pm

Oracle Database access from OpenOffice's Macros

Post by henrique »

Hello

How can I retrieve records from a oracle database table inside OpenOffice's Macros???
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: Oracle Database access from OpenOffice's Macros

Post by probe1 »

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

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
Post Reply