2

I am using the following command to create a database using windows command and connect to it but I am getting java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind error.

Command used to create a database named xdb and connect to it:

java -cp ./lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb

Complete error:

[Server@83cc67]: [Thread[main,5,main]]: checkRunning(false) entered
[Server@83cc67]: [Thread[main,5,main]]: checkRunning(false) exited
[Server@83cc67]: Startup sequence initiated from main() method
[Server@83cc67]: Loaded properties from [C:\Home\hsqldb\server.properties]
[Server@83cc67]: Initiating startup sequence...
[Server@83cc67]: [Thread[HSQLDB Server @83cc67,5,main]]: run()/openServerSocket(
):
java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
        at java.net.ServerSocket.bind(ServerSocket.java:319)
        at java.net.ServerSocket.<init>(ServerSocket.java:185)
        at java.net.ServerSocket.<init>(ServerSocket.java:97)
        at org.hsqldb.HsqlSocketFactory.createServerSocket(Unknown Source)
        at org.hsqldb.Server.openServerSocket(Unknown Source)
        at org.hsqldb.Server.run(Unknown Source)
        at org.hsqldb.Server.access$000(Unknown Source)
        at org.hsqldb.Server$ServerThread.run(Unknown Source)
[Server@83cc67]: Initiating shutdown sequence...
[Server@83cc67]: Shutdown sequence completed in 6 ms.
[Server@83cc67]: 2012-05-18 01:31:59.184 SHUTDOWN : System.exit() is called next

Could someone help me understand why am I getting this error and how to solve it?

Thanks

skip
  • 12,193
  • 32
  • 113
  • 153

2 Answers2

4

The default port for hsqldb is 9001

Run netstat -an check to see if there is something is LISTENING on port 9001

netstat -an | grep LISTENING to check for all servers listening for incoming connections

netstat -an | grep 9001 to check for a specific port number.

If there is something already there then the new of hsqldb that you are trying to start will fail to bind a socket to the 9001 port.

On Windows 7 you can run TCPView to see what process is currently listening on the "overcrowded" port. Then it's a matter of deciding to terminate that process which is using 9001 or reconfiguring hsqldb and your client application to use a different (unused) port.

It is possible to change the port that hsqldb listens on using the --port XXXX, where XXXX is the new port number.

Also from the java -cp ./lib/hsqldb.jar org.hsqldb.Server --help output...

The server looks for a 'server.properties' file in the current directory and loads properties from it if it exists. Command line options override those loaded from the 'server.properties' file.

There are other possible causes of this error so it would be useful to know what operating system the hsqldb is running on.

Failure to bind to a socket is a problem that can afflict any server application so you can review the answers provided for other server software that return this error such as the question asked about JBOSS here ...

java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind (JBOSS)

Community
  • 1
  • 1
Rob Kielty
  • 7,958
  • 8
  • 39
  • 51
  • I get "TCP 127.0.0.1:9001 127.0.0.1:53513 ESTABLISHED" for "Proto Local Address Foreign Address State". I am using Windows 7 64 bit. What do I do now to solve this problem. I never had this issue before with the same command. When I try "netstat -an | grep LISTENING" it gives me "'grep' is not recognized as an internal or external command,". What do I do now? – skip May 17 '12 at 21:06
  • 1
    So this means that there is a server listening on port 9001 and that there is a client application connected to it. So this explains goes towards explaining why you are getting the bind error. Onwards and upwards we no need to find out what process is listening on that port. Update to follow. – Rob Kielty May 17 '12 at 21:18
  • 1
    I updated the answer; is it possible for you to install TCPView? It will make it very easy to fully diagnose the problem. – Rob Kielty May 17 '12 at 22:15
  • 1
    Thanks again for the descriptive reply on the subject. I was running an application that was using hsqldb so I shut that server down and checked if that was causing the issue. After shutting down the server the status went back to "LISTENING" from "ESTABLISHED";" TCP 0.0.0.0:9001 0.0.0.0:0 LISTENING". But even after that I am not able to create a database and connect to hsqldb. It still gives me the same error. I used TCPView and http://img707.imageshack.us/img707/6635/hsqldbtcpview.jpg is how it looks. – skip May 17 '12 at 22:29
  • The image shows the status when I have got the application server running again which is using hsqldb. – skip May 17 '12 at 22:32
  • But I am still not able to connect to hsqldb when I try to do it using my IDE to run an sql script from within my IDE and it says `Connection is broken: java.io.EOFException` as the error. I could swear that I never had issues with using hsqldb with or without IDE. I think its something with the Windows 7 64 bit that is causing this issue. – skip May 17 '12 at 22:36
  • 1
    Did you try the -Djava.net.preferIPv4Stack=true from the other question that I linked to? – Rob Kielty May 17 '12 at 22:44
  • :I am not sure if I am able to set `-Djava.net.preferIPv4Stack=true` correctly as it starts telling me about the usage of `java` command. Am I supposed to set it specific to an application? – skip May 17 '12 at 23:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11419/discussion-between-rob-and-skip) – Rob Kielty May 18 '12 at 11:27
0

It looks like you try to bind to port 0 and it doesn't exist. Try to config a different port

richarbernal
  • 1,063
  • 2
  • 14
  • 32