aspose file tools*
The moose likes JDBC and the fly likes How to connect to Open Office Database using JDBC connection in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to connect to Open Office Database using JDBC connection in Java" Watch "How to connect to Open Office Database using JDBC connection in Java" New topic
Author

How to connect to Open Office Database using JDBC connection in Java

Foni kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 66
Hi Experts,

I am having some difficulty while trying to connect to my Open Office Database using JDBC connections. I dont know where i am committing mistake,it will be great if you could provide me suggestions or modify my code which is pasted below. I want to access the database to perform some further operations:-

**********************************************************************************************

**********************************************************************************************

public static void main (String[] args) {
try{
String db_file_name_prefix = "c:\\mydbdir\\test";
Connection connection = null;
connection = DriverManager.getConnection("jdbc:hsqldb:file:" + db_file_name_prefix, "","");
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("Select * from student");

***********************************************************************************************

***********************************************************************************************

I havent got much exposure about the JDBC connections before so it will be nice if you can take a look if i have committed some errors in any of the statements in the above code snippets. Please provide me any refernce code snippets also if you have any for Open office JDBC connectivity...


I will be looking for your reply on this

P.S : The database is Open Office database with the table named student created in it.

Kind Regards,
deb
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Hi debashis,

Welcome to Code Ranch.
You missed to load the driver class.
Means you need to use


In future use code tag to post your code, it will help others to read your code.
Do Google search with keyword jdbc connection example, you will get more examples.

Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Foni kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 66
Hi Sri ram.

First of all thank you for all your reply and suggestions in this regard. I tried to implement the driver class as shown below in my code but it doesn't seem to work. My code still doesn't respond and also doesn't connect to the Open office Database. I will brief out a bit about my requirement .

I want to connect to the Open office database and fetch the datafrom the Openoffice database table named employee and populate it in my excel sheet. But in this process i am failing in the first step itself ,that is connection to the Open Office database.Could you please take a look on the code which i have pasted below because i have made many attempts to figure out the exact issue but I am not able to get it resolved.


**********
Code
**********






Kind Regards,
Debashis
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Your main mistake is here:



It's quite likely (and in your case almost certain) that the code will throw some kind of exception. And you have written your program to say "If the code throws an exception, don't do anything".

This is a bad idea. If an exception is thrown, you want to know all about it. So print its stack trace when it happens:

Foni kumar
Ranch Hand

Joined: Sep 19, 2007
Posts: 66
Hi Paul,

Thank you!for the suggestions.I tried implementing what you have suggested and got the below errors in my java console.I am unable to make out the very reasons behind these errors ,the first one says File input/output error but my file path for the database file is correct. it is the same location c:\mydbdir\test.properties .It will be great if you could provide me your suggestions on the below errors I am getting with reference to execution of my code which i have pasted before in my previous post reply.

****************************
ERROR I GOT IN CONSOLE

****************************



java.sql.SQLException: File input/output error: file:c:\mydbdir\test.properties
at org.hsqldb.Trace.getError(Trace.java:180)
at org.hsqldb.Trace.getError(Trace.java:144)
at org.hsqldb.Trace.error(Trace.java:205)
at org.hsqldb.Log.saveProperties(Log.java:630)
at org.hsqldb.Log.create(Log.java:521)
at org.hsqldb.Log.open(Log.java:159)
at org.hsqldb.Database.<init>(Database.java:96)
at org.hsqldb.jdbcConnection.openStandalone(jdbcConnection.java:926)
at org.hsqldb.jdbcConnection.<init>(jdbcConnection.java:682)
at org.hsqldb.jdbcDriver.connect(jdbcDriver.java:116)
at java.sql.DriverManager.getConnection(DriverManager.java:322)
at java.sql.DriverManager.getConnection(DriverManager.java:358)
at com.database.CreateExcelFile.main(CreateExcelFile.java:21)
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
You are facing problem in creating excel file.
Check line number 21



To check status of the connection use


Regards,
Sriram.V
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to connect to Open Office Database using JDBC connection in Java