Connect to Open Office odb file using jdbc program

I wrote the following code to connect to OpenOffice db.

String db = "C:\\Documents and Settings\\hkonakanchi\\Desktop\\Test.odb"; Class.forName("org.hsqldb.jdbcDriver"); Connection con = DriverManager.getConnection("jdbc:hsqldb:file:" + db,"sa",""); Statement statement = con.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM Emp"); while (rs.next()) { System.out.print("ID: " + rs.getString("ID")); System.out.print(" first name: " + rs.getString("firstname")); System.out.println(" last name: " + rs.getString("lastname")); } con.close(); 

The database contains the emp table and some data is saved.

But I get the error message as follows.

 Exception in thread "main" java.sql.SQLException: Table not found in statement [SELECT * FROM Emp] at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.executeQuery(Unknown Source) at Test.main(Test.java:16) 

How can i solve this. Can someone tell me how to connect to db open office using hsqldb driver?

+4
source share
3 answers

Finally, I found a solution. but unfortunately you need to change your db from odb to hsql.

1.Find your odb file in yourdatabasename.zip file

2.extract it

Now you can find the backups, data, script, properties files in the database directory under your database folder.

4.Install these files on yourdatabasename.data, yourdatabasename.backup, yourdatabasename.script, yourdatabasename.properties

5. Now your connection should be like this: "JDBC: HSQLDB: Addresstoyourdatabase file / database / database_name"

6. Remember to put "around your table name, like:" SELECT * FROM \ "Emp \" "

+4
source

I had a similar problem with a derby database that I accessed locally. In my case, it was a schema that was not in my SQL statement. So I needed something like:

  select * from Emp.APP 

to make the select statement not generate the error you see.

I looked at this website http://hsqldb.org/doc/1.8/guide/ch09.html#select-section and noticed that it has

 table.* 

as part of an example selection instruction. Therefore, I assume that replacing * with the database name or schema may solve your problem (or just try it with. *).

0
source

I developed a simple (read-only) JDBC driver that basically extracts the .odb file and redirects all calls to the HSQLDB driver. Maybe this is also useful for someone.

0
source

Source: https://habr.com/ru/post/1396124/


All Articles