简体   繁体   中英

Gemfire JDBC connection exception

I start the Gemfire server and bind him to the following address: myserver:10344. (Server and locator are started without problems) After that I check connection by the GFSH and client "pulse". All checks are successful. At the next step I develop my Java client and can't make a connection to the server.

My project is built by Maven with the following dependencies:

   <dependency>
      <groupId>com.pivotal.gemfirexd</groupId>
      <artifactId>gemfirexd</artifactId>
      <version>1.4.1</version>
   </dependency>
   <dependency>
      <groupId>com.pivotal.gemfirexd</groupId>
      <artifactId>gemfirexd-client</artifactId>
      <version>1.4.1</version>
   </dependency>

(All Gemfire dependencies are downloaded from http://dist.gemstone.com/maven/release )

Code source:

package com.mycompany.app;
import java.sql.Connection;
import java.sql.DriverManager;

public class App {

    private void connect() {
        try {
            Class.forName("com.pivotal.gemfirexd.jdbc.ClientDriver");

            String x = "jdbc:gemfirexd://myserver:10344/";

            System.out.println(x);

            final Connection conn = DriverManager.getConnection(x);

            System.out.println("Connected ");
            conn.close();
            System.out.println("Disconnected");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main( String[] args ) {
        new App().connect();
    }
}

I get the following exception:

java.sql.SQLNonTransientConnectionException: A communications error has been detected: Failed after trying all available servers: [], for control URL: myserver[10334].
    at com.pivotal.gemfirexd.internal.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:77)
    at com.pivotal.gemfirexd.internal.client.am.SqlException.getSQLException(SqlException.java:401)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.getPreferredServer(NetConnection.java:1554)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.preConnect(NetConnection.java:1902)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.newAgent_(NetConnection.java:2368)
    at com.pivotal.gemfirexd.internal.client.am.Connection.<init>(Connection.java:595)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.<init>(NetConnection.java:248)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection40.<init>(NetConnection40.java:86)
    at com.pivotal.gemfirexd.internal.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(ClientJDBCObjectFactoryImpl40.java:290)
    at com.pivotal.gemfirexd.jdbc.ClientDriver.connect(ClientDriver.java:161)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.mycompany.app.App.connect(App.java:15)
    at com.mycompany.app.App.main(App.java:27)
Caused by: DisconnectException 08006: A communications error has been detected: Failed after trying all available servers: [], for control URL: myserver[10334].
    ... 12 more
Caused by: java.sql.SQLNonTransientConnectionException: A communications error has been detected: Connection reset.
    at com.pivotal.gemfirexd.internal.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:77)
    at com.pivotal.gemfirexd.internal.client.am.SqlException.getSQLException(SqlException.java:401)
    at com.pivotal.gemfirexd.jdbc.ClientDriver.connect(ClientDriver.java:170)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.getPreferredServer(NetConnection.java:1451)
    ... 11 more
Caused by: DisconnectException 08006: A communications error has been detected: Connection reset.
    at com.pivotal.gemfirexd.internal.client.net.NetAgent.throwCommunicationsFailure(NetAgent.java:527)
    at com.pivotal.gemfirexd.internal.client.net.Reply.fill(Reply.java:183)
    at com.pivotal.gemfirexd.internal.client.net.Reply.ensureALayerDataInBuffer(Reply.java:222)
    at com.pivotal.gemfirexd.internal.client.net.Reply.readDssHeader(Reply.java:324)
    at com.pivotal.gemfirexd.internal.client.net.Reply.startSameIdChainParse(Reply.java:1154)
    at com.pivotal.gemfirexd.internal.client.net.NetConnectionReply.readExchangeServerAttributes(NetConnectionReply.java:61)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.readServerAttributesAndKeyExchange(NetConnection.java:1013)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.flowServerAttributesAndKeyExchange(NetConnection.java:941)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.flowUSRIDONLconnect(NetConnection.java:796)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.flowConnect(NetConnection.java:580)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection.<init>(NetConnection.java:259)
    at com.pivotal.gemfirexd.internal.client.net.NetConnection40.<init>(NetConnection40.java:86)
    at com.pivotal.gemfirexd.internal.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(ClientJDBCObjectFactoryImpl40.java:290)
    at com.pivotal.gemfirexd.jdbc.ClientDriver.connect(ClientDriver.java:161)
    ... 14 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at com.pivotal.gemfirexd.internal.client.net.Reply.fill(Reply.java:181)
    ... 26 more

I see that this is an old post but just in case you still want to know ....

The port you're specifying in your jdbc url is referring to the peer-membership discovery port, not the client-port (default 1527).

When you started the locator, there should've been info on the client port number as such (if you don't specify, default is 1527)

... Starting GemFireXD Locator using peer discovery on: localhost[10334] Starting network server for GemFireXD Locator at address localhost/127.0.0.1[1527]

Your jdbc url should be as follows:

String x = "jdbc:gemfirexd://myserver:1527/";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM