如何使用IntelliJ和JDBC SSH隧道并连接到数据库?

我在使用IntelliJ和JDBC连接到服务器上托管的数据库时遇到问题.使用命令行,命令:

ssh username@server -L 11100:ct1:28017 -N

成功创建隧道并执行命令:

psql db_name -h localhost -p 11100 db_username

连接数据库很好,允许我使用它.如何将其正确转换为IntelliJ数据源和SSH隧道工具?

目前,对于SSH隧道设置,我有:

代理主机:服务器

港口:22

代理用户:用户名

对于常规选项卡,我有:

主持人:localhost

港口:28017

database:db_name

user:db_username

测试连接后连接成功返回.我的程序里面有:

Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost:28017/db_name", user, password);

URL参数是IntelliJ生成的参数.但是这给了我一个错误“连接到localhost:28017被拒绝”.

关于我做错了什么的任何想法?

最佳答案 您是否从SSHJ(
https://github.com/hierynomus/sshj)等Java客户端连接到SSH服务器?

DriverManager上的URL似乎错误:尝试使用端口11100.

点赞