User:Stevi105/Books/Informix in Basic

From Apache OpenOffice Wiki
Jump to: navigation, search

Template:Saved book


Example collection OpenOffice Basic

Working with a Database

Connect an Informix-Database with JDBC and OpenOfficeBasic

Dim URL As String
Dim SQLQueryString As String
Dim SearchString As String
Dim SQLStatement As String
Dim props(3) as new com.sun.star.beans.PropertyValue
Dim oConnection As Object
Dim oDriverManager As Object
Dim oResultset As Object
 
oDriverManager = createUnoService("com.sun.star.sdbc.DriverManager")
props(0).Name = "user"
props(0).Value = "YourName"
props(1).Name = "password"
props(1).Value = "Yourpassword"
props(2).Name = "JavaDriverClass"
props(2).Value = "com.informix.jdbc.IfxDriver"
 
'URL = "jdbc:informix-sqli://MyServer:MyPort/MySchema:INFORMIXSERVER=MyDB"
URL = "jdbc:informix-sqli://Server17:1571/User23:INFORMIXSERVER=servtest"
 
oConnection = oDriverManager.getConnectionWithInfo(URL , props)
oConnection.setAutoCommit(true)
 
SQLStatement = MyConnection.createStatement
 
SearchString = "xyz"
 
SQLQueryString = "SELECT name from Table_ABC where name like '%" & SearchString &"%' order by name"
oResultset = SQLStatement .executeQuery(SQLQueryString )
 
IF NOT ISNULL(oResultset ) THEN
   WHILE (oResultset.next )
     Msgbox(oResultset.getString(1))
     WEND 
   END IF 
oResultset.close
Personal tools