H2拒绝与localhost的连接

时间:2017-10-27 09:21:54

标签: java database-connection h2 connection-refused

我有这个非常简单的java类,我尝试运行这样的H2 DB:

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");

我试图复制我在这里和H2文档中发现的内容,但由于某种原因连接被拒绝了。我试图在这里找到解决方案,但到目前为止还没有成功。仅供参考:我是一名新手,如果可能的话,我会很高兴获得更详细的答案;)提前致谢!

这是堆栈跟踪:

> 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

0 个答案:

没有答案