2

i have this very simple java class where i try to run a H2 DB like this:

public static void main(String[] args) {
     Connection conn = null;
                try {
            Class.forName("org.h2.Driver");
            Server server = Server.createTcpServer("-tcpPort", "50001", "-tcpAllowOthers").start();

            conn = DriverManager.getConnection(
                    "jdbc:h2:tcp://localhost/~/H2TestDB/SMPS_DK", "sa", "sa");

I tried to copy what i found here and in the H2 doc already but for some reason the connection gets refused. I tried to find the solution here but havent been successfull so far. FYI: I am kind of a rookie so it would be great to get a more detailed answer if possible ;) Thanks in advance!

Here comes the stacktrace:

> org.h2.jdbc.JdbcSQLException: Verbindung ist unterbrochen: "java.net.ConnectException: Connection refused: connect: localhost"
Connection is broken: "java.net.ConnectException: Connection refused: connect: localhost" [90067-196]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:168)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:457)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:334)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
    at org.h2.Driver.connect(Driver.java:69)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at connection.Main.main(Main.java:26)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:103)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:83)
    at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:115)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:453)
    ... 7 more
Zipfelchen
  • 21
  • 1
  • 5
  • 1
    code seems to be correct, have you checked if your local database server / service is up and running? – Stormtrooper CWR Oct 27 '17 at 09:31
  • Also check your password.Did you set any? – imk Oct 27 '17 at 09:40
  • Thanks for the quick reply. I have set pw and acc to "sa" this shoudlnt be the issue. As for the local db server/service: i was under the impression that this is how i start the server: Server server = Server.createTcpServer([...]); – Zipfelchen Oct 27 '17 at 09:42
  • I also looked at this :https://stackoverflow.com/a/21672625/8842588 I added the jar to the build path but want to start everything from my application and not on cmd – Zipfelchen Oct 27 '17 at 11:15
  • You need to use the changed port `localhost:50001` – Oleg Oct 27 '17 at 13:51

0 Answers0