Sann Maung wrote:

Hi,

I have tried to write a java program to create a
database file. After running the program, it looks
like there is no error. But when I open that file from
OpenOffice Base, I can open it. But when I click the
Table, there is an error message "The connection to
the datasource cannot be established" appears.

Then I create a separate database file from OpenOffice
Base and create a simple table. Then I tried to access
from java program. "Table not found error appears".

My java program is attached. Can anybody please
suggest where I make errors?


rgds

The list removes attachements in general.

Also, the dev list is probably a better place to ask. It sounds like you are NOT correctly creating the database, however. You do something like this in Basic to make it work. I ripped this from some of my own code that at least used to work in an old beta version...

Sub NewDB(dbFileName As String)
 Dim sDBUrl            'This is the database type
 Dim sTableName$       'The name of the table to creat.
 Dim oDoc              'The newly created database document.
 Dim oTable            'A table in the database.
 Dim oTables           'Tables in the document
 Dim oTableDescriptor  'Defines a table and how it looks!
 Dim oCols             'The columns for a table.
 Dim oCol              'A single column descriptor.
 Dim oCon              'Database connection
 Dim oBaseContext
 Dim oDataBase
 Dim x

 If FileExists(dbFileName) Then
   Print "The file already exists, go get it!"
   oDoc = FindComponentWithURL(dbFileName, True)
 Else
   Print "Creating a new file!"
   sDBUrl = "private:factory/sdatabase"
   oDoc = StarDesktop.loadComponentFromURL(sDBUrl,"_blank",0,Array())
   oDoc.URL = "sdbc:embedded:hsqldb"
   oDoc.storeAsURL(dbFileName, Array())
 End If

 oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
 oDataBase = oBaseContext.getByName(dbFileName)
 oCon = oDataBase.getConnection("", "")

 oTables = oCon.getTables()

 REM Each stamp belongs to a country
 sTableName$ = "COUNTRY"
 If NOT oTables.hasByName(sTableName$) Then
   oTableDescriptor = oTables.createDataDescriptor()
   oTableDescriptor.Name = sTableName$

   oCols = oTableDescriptor.getColumns()
   oCol = oCols.createDataDescriptor()

   oCol.Name = "CountryID"
   oCol.Type = com.sun.star.sdbc.DataType.INTEGER
   oCol.IsNullable = com.sun.star.sdbc.ColumnValue.NO_NULLS
   oCol.IsAutoIncrement = True
   oCol.Precision = 10
   oCols.appendByDescriptor(oCol)

   oCol.Name = "CountryName"
   oCol.Type = com.sun.star.sdbc.DataType.VARCHAR
   oCol.Precision = 50
   oCol.IsAutoIncrement = False
   oCols.appendByDescriptor(oCol)

   oTables.appendByDescriptor(oTableDescriptor)
 End If

 REM Where the stamp is stored
 sTableName$ = "LOCATION"
 If NOT oTables.hasByName(sTableName$) Then
   oTableDescriptor = oTables.createDataDescriptor()
   oTableDescriptor.Name = sTableName$

   oCols = oTableDescriptor.getColumns()
   oCol = oCols.createDataDescriptor()

   oCol.Name = "LocationID"
   oCol.Type = com.sun.star.sdbc.DataType.INTEGER
   oCol.IsNullable = com.sun.star.sdbc.ColumnValue.NO_NULLS
   oCol.IsAutoIncrement = True
   oCol.Precision = 10
   oCols.appendByDescriptor(oCol)

   oCol.Name = "LocationName"
   oCol.Type = com.sun.star.sdbc.DataType.VARCHAR
   oCol.Precision = 50
   oCol.IsAutoIncrement = False
   oCols.appendByDescriptor(oCol)

   oTables.appendByDescriptor(oTableDescriptor)
 End If

oDoc.Store()
oCon.close()
....


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to