• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Foni kumar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 28323
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are facing problem in creating excel file.
Check line number 21



To check status of the connection use


Regards,
Sriram.V
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic