aspose file tools*
The moose likes JDBC and the fly likes HSQLDB Connection not established Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "HSQLDB Connection not established" Watch "HSQLDB Connection not established" New topic
Author

HSQLDB Connection not established

Manisha Haran
Greenhorn

Joined: Jul 13, 2008
Posts: 2
Hi everyone,

I had created a HSQLDB in the following manner : java -classpath ./hsqldb.jar org.hsqldb.util.DatabaseManager -driver org.hsqldb.jdbcDriver -url jdbc:hsqldb:C:\Users\mharidas\Documents\Test_AC -user sa


That is my DB name is TEST_AC.

I believe that when the DataBase gets created it is of IN-Memory type and not standAlone etc.

Now when I try to connect to it by the following code :
<blockquote>code:
<pre name="code" class="core">
Connection conn=null;
Statement select=null;
try{
Class.forName("org.hsqldb.jdbcDriver");
System.out.println("Driver loaded...");}
catch(Exception e){
System.out.println("Failed to load hsql driver.");
return; }
try{
conn = DriverManager.getConnection("jdbc:hsqldb:C:\\Users\\mharidas\\Documents\\Test_AC","sa","");
System.out.println("connected to hsql..");
</pre>
</blockquote>
It gives me a nullPointerException..at DriverManager.getConnection.

Can someone help me as to why this exception has occured.
I have tried giving jdbc:hsqldb:mem:. as well as jdbc:hsqldb:./TEST_AC as the url but it still dint work..

Am i missing something?

[ July 16, 2008: Message edited by: Manisha Haran ]
[ July 16, 2008: Message edited by: Manisha Haran ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
Welcome to JavaRanch.

Please check the stack trace for the NullPointerException (NPE). Somebody else had an NPE on a database today as well; some of the links might be helpful, from this post.
Are you sure that is where the problem is? The getConnection method is static, so that oughtn't to throw an NPE.
You are supplying the requisite 3 arguments, so they oughtn't to throw an NPE.
If there is any error in that line, it would throw an SQLException rather than an NPE.
Please check the server-side part of your database program is running. I am not familar with HSQLDB, but there is probably some admin utility where you can see whether the server is alive.

If none of those suggestions helps, please come back with more details.
[ July 13, 2008: Message edited by: Campbell Ritchie ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
By the way: Please use the code button (below the message box) when you quote code.

Please go back to your post, use the pencil-and-paper icon to edit it, highlight the code, then click the code button. It preserves your indentation and makes it much easier to read.
Manisha Haran
Greenhorn

Joined: Jul 13, 2008
Posts: 2
Thanks for replying Campbell. Actually you are right in pointing out that the exception thrown on that line cannot be a nullPointer. It was an sqlException. The stack trace of the exception is :

java.sql.SQLException: socket creation error
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
at org.hsqldb.jdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DataBaseConn.main(DataBaseConn.java:18)

Any idea why this kind of an exception could occur? And thanks for pointing out that code block is to be used.. I have made the necessary changes.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

java.sql.SQLException: socket creation error


I have not familiar with HSQLDB but after a search google on above exception and I have found something like when URL trying to connect to a standalone server on the network It doesn't find the server ( means your server is not running ) that's why the socket creation error message is occur.

<blockquote>code:
<pre name="code" class="core">conn = DriverManager.getConnection("jdbc:hsqldb:C:\\Users\\mharidas\\Documents\\Test_AC","sa","");</pre>
</blockquote>

I think the way you define the url is not correct because HSQLDB guide is stated it differently.

hope it helps.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
Originally posted by Manisha Haran:
Thanks for replying Campbell. Actually you are right in pointing out that the exception thrown on that line cannot be a nullPointer. It was an sqlException.
So why were you asking about the wrong sort of Excption? Read this and this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HSQLDB Connection not established