• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HSQLDB Connection not established

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic