Eclipse H2 database not connect

3.5k Views Asked by At

I tried to connect H2 database using eclipse and when i try to connect it gives below error.

org.h2.jdbc.JdbcSQLNonTransientConnectionException: Connection is broken: "java.net.SocketTimeoutException: connect timed out: localhost:12345" [90067-200]
  connect timed out
  connect timed out

My connection settings

enter image description here

H2 Server,

enter image description here

Please help me to fixed this issue.

3

There are 3 best solutions below

0
On

You must start the h2 server with -tcp option.

For example:

java -cp h2-1.4.200.jar org.h2.tools.Server -tcp -tcpAllowOthers

You can also use extra options like:

java -cp h2-1.4.200.jar org.h2.tools.Server -tcp -tcpAllowOthers -ifNotExists -baseDir <path-to-db-files>

Without -tcp you can get problems.

0
On

I tried everything, but the only thing that seems to work is restarting my computer.

Here's a list of things that did NOT work:

  1. refreshing the project and maven
  2. closing and opening applications
  3. adjusting the code

I could even see the database working fine in the H2 Console, but eclipse would not connect to it until I restarted my computer.

I logged this error many times: "connection: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Connection is broken: "java.net.SocketTimeoutException: Connect timed out: ..."

I restarted to connect to the database before lunch, and worked on my pc for an hour. It slept through lunch, then I had to restart my computer again to connect to the database in the afternoon.

Restart your PC before reinstalling anything.

0
On

Most likely your h2 service has stopped. Check Services, and if it's not there, reinstall it.