jsch连接mysql_尝试使用jsch和jdbc连接到postgres数据库会产生“连接尝试失败。导致:java.io.EOFException”...

我试图连接到在Amazon EC2服务器上运行的postgres数据库。我知道服务器配置正确,因为我可以从pgadmin访问它,并在intellij中作为数据源。尝试使用jsch和jdbc连接到postgres数据库会产生“连接尝试失败。导致:java.io.EOFException”

我也可以连接到我的程序内的服务器外壳时,只使用jsch和直接使用jdbc连接到另一个数据库,但只要我尝试连接到我的postgres实例通过SSH与jsch隧道我给了这个奇怪的我一直无法错误诊断:

org.postgresql.util.PSQLException: The connection attempt failed.

at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)

at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)

at org.postgresql.jdbc.PgConnection.(PgConnection.java:216)

at org.postgresql.Driver.makeConnection(Driver.java:406)

at org.postgresql.Driver.connect(Driver.java:274)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:208)

at EnumStreamer.main(EnumStreamer.java:38)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: java.io.EOFException

at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:285)

at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:411)

at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:208)

... 12 more

我使用连接的代码如下:

System.out.println("Connecting...");

session = secConnect.getSesssion();

UserInfo ui = new uInfo();

session.setUserInfo(ui);

session.connect();

session.setPortForwardingL(5432,secConnect.getHost(),5432);

System.out.println("SSH Tunneled");

System.out.println("Opening Database Connection");

Class.forName("org.postgresql.Driver");

Properties props = new Properties();

props.setProperty("user","username");

props.setProperty("password","password");

props.setProperty("loglevel", "2");

connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/dbname",props);

System.out.println("Connected");

的secConnect对象的相关代码是在这里:

jsch.addIdentity(chooser.getSelectedFile().getAbsolutePath());

public Session getSesssion() throws JSchException {

return jsch.getSession(user, host, 22);

}

我的EC2 Postgres的服务器配置的ListenAddress = '*' 和pg_hba.conf里有行

host all all 0.0.0.0/0 md5

DB日志试图瞬移产生这个时候:

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: InitPostgres

DEBUG: my backend ID is 2

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: autovacuum: processing database "postgres"

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: pg_statistic: vac: 0 (threshold 127), anl: 0 (threshold 88)

DEBUG: pg_type: vac: 0 (threshold 116), anl: 0 (threshold 83)

DEBUG: pg_authid: vac: 7 (threshold 50), anl: 8 (threshold 50)

DEBUG: pg_proc: vac: 0 (threshold 548), anl: 8 (threshold 299)

DEBUG: pg_class: vac: 0 (threshold 108), anl: 0 (threshold 79)

DEBUG: pg_attribute: vac: 0 (threshold 499), anl: 0 (threshold 275)

DEBUG: pg_constraint: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_operator: vac: 0 (threshold 196), anl: 0 (threshold 123)

DEBUG: pg_opclass: vac: 0 (threshold 74), anl: 0 (threshold 62)

DEBUG: pg_am: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_amop: vac: 0 (threshold 129), anl: 0 (threshold 89)

DEBUG: pg_amproc: vac: 0 (threshold 107), anl: 0 (threshold 79)

DEBUG: pg_language: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_aggregate: vac: 0 (threshold 74), anl: 0 (threshold 62)

DEBUG: pg_rewrite: vac: 0 (threshold 71), anl: 0 (threshold 61)

DEBUG: pg_trigger: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_description: vac: 0 (threshold 740), anl: 1 (threshold 395)

DEBUG: pg_database: vac: 0 (threshold 50), anl: 1 (threshold 50)

DEBUG: pg_namespace: vac: 0 (threshold 51), anl: 0 (threshold 51)

DEBUG: pg_depend: vac: 0 (threshold 1291), anl: 8 (threshold 670)

DEBUG: pg_db_role_setting: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_tablespace: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_shdepend: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_shdescription: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_ts_config: vac: 0 (threshold 53), anl: 0 (threshold 52)

DEBUG: pg_ts_dict: vac: 0 (threshold 53), anl: 0 (threshold 52)

DEBUG: pg_ts_parser: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_ts_template: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_extension: vac: 0 (threshold 50), anl: 1 (threshold 50)

DEBUG: pg_index: vac: 0 (threshold 72), anl: 0 (threshold 61)

DEBUG: pg_cast: vac: 0 (threshold 89), anl: 0 (threshold 70)

DEBUG: pg_toast_2619: vac: 0 (threshold 52), anl: 0 (threshold 51)

DEBUG: pg_toast_2618: vac: 0 (threshold 84), anl: 0 (threshold 67)

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: shmem_exit(0): 8 callbacks to make

DEBUG: proc_exit(0): 2 callbacks to make

DEBUG: exit(0)

DEBUG: shmem_exit(-1): 0 callbacks to make

DEBUG: proc_exit(-1): 0 callbacks to make

DEBUG: reaping dead processes

DEBUG: server process (PID 21628) exited with exit code 0

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: InitPostgres

DEBUG: my backend ID is 2

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: autovacuum: processing database "patientSim"

DEBUG: StartTransaction

DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: pg_statistic: vac: 0 (threshold 127), anl: 0 (threshold 88)

DEBUG: pg_type: vac: 5 (threshold 116), anl: 14 (threshold 83)

DEBUG: pg_authid: vac: 7 (threshold 50), anl: 8 (threshold 50)

DEBUG: pg_proc: vac: 0 (threshold 548), anl: 0 (threshold 299)

DEBUG: pg_class: vac: 7 (threshold 108), anl: 20 (threshold 79)

DEBUG: pg_attribute: vac: 36 (threshold 499), anl: 111 (threshold 275)

DEBUG: pg_constraint: vac: 2 (threshold 50), anl: 5 (threshold 50)

DEBUG: pg_operator: vac: 0 (threshold 196), anl: 0 (threshold 123)

DEBUG: pg_opclass: vac: 0 (threshold 74), anl: 0 (threshold 62)

DEBUG: pg_am: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_amop: vac: 0 (threshold 129), anl: 0 (threshold 89)

DEBUG: pg_amproc: vac: 0 (threshold 107), anl: 0 (threshold 79)

DEBUG: pg_language: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_aggregate: vac: 0 (threshold 74), anl: 0 (threshold 62)

DEBUG: pg_rewrite: vac: 0 (threshold 71), anl: 0 (threshold 61)

DEBUG: pg_trigger: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_description: vac: 0 (threshold 740), anl: 0 (threshold 395)

DEBUG: pg_database: vac: 0 (threshold 50), anl: 1 (threshold 50)

DEBUG: config: vac: 10 (threshold 50), anl: 19 (threshold 50)

DEBUG: pg_namespace: vac: 0 (threshold 51), anl: 0 (threshold 51)

DEBUG: pg_depend: vac: 16 (threshold 1291), anl: 46 (threshold 670)

DEBUG: pg_db_role_setting: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_tablespace: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_shdepend: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_shdescription: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_ts_config: vac: 0 (threshold 53), anl: 0 (threshold 52)

DEBUG: pg_ts_dict: vac: 0 (threshold 53), anl: 0 (threshold 52)

DEBUG: pg_ts_parser: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_ts_template: vac: 0 (threshold 51), anl: 0 (threshold 50)

DEBUG: pg_extension: vac: 0 (threshold 50), anl: 0 (threshold 50)

DEBUG: pg_collation: vac: 0 (threshold 234), anl: 0 (threshold 142)

DEBUG: pg_attrdef: vac: 1 (threshold 50), anl: 3 (threshold 50)

DEBUG: pg_index: vac: 2 (threshold 72), anl: 6 (threshold 61)

DEBUG: pg_cast: vac: 0 (threshold 89), anl: 0 (threshold 70)

DEBUG: pg_toast_2619: vac: 0 (threshold 52), anl: 0 (threshold 51)

DEBUG: pg_toast_2618: vac: 0 (threshold 84), anl: 0 (threshold 67)

DEBUG: pg_toast_16409: vac: 0 (threshold 50), anl: 148 (threshold 50)

DEBUG: CommitTransaction

DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:

DEBUG: shmem_exit(0): 8 callbacks to make

DEBUG: proc_exit(0): 2 callbacks to make

DEBUG: exit(0)

DEBUG: shmem_exit(-1): 0 callbacks to make

DEBUG: proc_exit(-1): 0 callbacks to make

DEBUG: reaping dead processes

DEBUG: server process (PID 21659) exited with exit code 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值