当前位置:网站首页>在JDBC连接数据库时报错:Connection to 139.9.130.37:15400 refused.
在JDBC连接数据库时报错:Connection to 139.9.130.37:15400 refused.
2022-06-13 03:28:00 【CSDN问答】
问题遇到的现象和发生背景
今天想再次用teacher给的java代码,通过JDBC连接数据库执行对数据库内数据的操作(之前有成功过,这次再试一次就不行了),前面的配置都做好了,就是到了命令台运行的时候发生了错误,错误显示如下:(说明一下,我用的是华为云弹性服务器连接本地虚拟机上的数据库)
问题相关代码,请勿粘贴截图
java代码如下:
import java.sql.*;
public class openGaussDemo {
static final String JDBC_DRIVER = "org.postgresql.Driver"; static final String DB_URL = "jdbc:postgresql://139.9.130.37:15400/demo"; // 数据库的用户名与密码,需要根据自己的设置static final String USER = "dbuser";static final String PASS = "Gauss#3demo"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try{ // 注册 JDBC 驱动 Class.forName(JDBC_DRIVER); // 打开链接 System.out.println("连接数据库..."); conn = DriverManager.getConnection(DB_URL,USER,PASS); // 执行查询 System.out.println(" 实例化Statement对象..."); stmt = conn.createStatement(); String sql; sql = "SELECT id, name, url FROM demo.websites"; ResultSet rs = stmt.executeQuery(sql); // 展开结果集数据库 while(rs.next()){ // 通过字段检索 int id = rs.getInt("id"); String name = rs.getString("name"); String url = rs.getString("url"); // 输出数据 System.out.print("ID: " + id); System.out.print(", 站点名称: " + name); System.out.print(", 站点 URL: " + url); System.out.print("\n"); } // 完成后关闭 rs.close(); stmt.close(); conn.close(); }catch(SQLException se){ // 处理 JDBC 错误 se.printStackTrace(); }catch(Exception e){ // 处理 Class.forName 错误 e.printStackTrace(); }finally{ // 关闭资源 try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ }// 什么都不做 try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(); } } System.out.println("Goodbye!");}}
(以上都是复制粘贴修改了一些根据华为云服务器的参数)
运行结果及报错内容
在命令台通过javac -encoding utf-8 -cp d:\Download\postgresql.jar openGaussDemo.java
和 java -cp .;D:/Download/postgresql.jar openGaussDemo命令后报错:

大致意思就是要不就是hostname错误要不就是端口号错误,但是已经反复检查都是没有错的,然后就有可能是后面的postmaster不接受TCP/IP的连接,但是都是按teacher给的文档来做的,而且之前都有运行成功过,就不知道到底是哪里出了问题。
我的解答思路和尝试过的方法
我上网搜了好多相关的信息,试过关防火墙,也试过重启虚拟数据库,配置了一些参数,看了一下监听地址是*没错,也将远程连接的权限赋给了我的dbuser用户,统统都失败了,还有的说要在win+R之后输入services.msc开启postgresql服务,看了下发现自己的电脑里面也没有这个服务。
我想要达到的结果
我就是想跑通这个java程序,ball ball各位help help小的吧!要做不完了!
边栏推荐
- Solve the error in CONDA installation PyMOL
- Golang picks up: why do we need generics
- Azure SQL db/dw series (12) -- using query store (1) -- report Introduction (1)
- Querywrapper constructor method
- [azure data platform] ETL tool (3) - azure data factory copy from local data source to azure
- Azure SQL db/dw series (10) -- re understanding the query store (3) -- configuring the query store
- Install MySQL database
- Configuration and practice of shardingsphere JDBC sub database separation of read and write
- [azure data platform] ETL tool (4) - azure data factory debug pipeline
- Summary of virtualization technology development
猜你喜欢

Brief introduction: distributed cap theory and base theory

Reading notes of effective managers

Querywrapper constructor method

Economic panel topic 1: panel data of all districts and counties in China - more than 70 indicators such as population, pollution and agriculture (2000-2019)

On the career crisis of programmers at the age of 35

Data of all bank outlets in 356 cities nationwide (as of February 13, 2022)

Few-shot Unsupervised Domain Adaptation with Image-to-Class Sparse Similarity Encoding

Figure data * reconstruction subgraph
![[azure data platform] ETL tool (6) -- re understanding azure data factory](/img/b5/da5dc9815fb9729fb367f2482913b7.jpg)
[azure data platform] ETL tool (6) -- re understanding azure data factory

Sparksql of spark
随机推荐
Rustup installation
Use of interceptors webmvcconfigurer
YoloV5-Face+TensorRT:基于WIN10+TensorRT8.2+VS2019得部署
Masa Auth - SSO and Identity Design
Complex network analysis capability based on graph database
[JVM Series 7] garbage collector
[JVM Series 5] JVM tuning instance
Solve the error in CONDA installation PyMOL
Several functions in YAF framework controller
C simple understanding - overloaded operator
Cross border M & a database: SDC cross border database, Thomson database, A-share listed company M & a database and other multi index data (4w+)
C # simple understanding - static members and static classes
【同步功能】2.0.16-19 版本都有同步功能修复的更新,但未解决问题
Peking University HP financial index - matching enterprise green innovation index 2011-2020: enterprise name, year, industry classification and other multi indicator data
Azure SQL db/dw series (11) -- re understanding the query store (4) -- Query store maintenance
Querywrapper constructor method
MySQL learning summary 10: detailed explanation of view use
English语法_频率副词
Mongodb distributed cluster deployment process
Spark Foundation