当前位置:网站首页>An error is reported in the JDBC connection database: connection to 139.9.130.37:15400 referred
An error is reported in the JDBC connection database: connection to 139.9.130.37:15400 referred
2022-06-13 03:33:00 【CSDN Q & A】
The phenomenon and background of the problem
I want to use it again today teacher Given java Code , adopt JDBC Connect to the database to perform operations on the data in the database ( I have succeeded before , Just try again this time ), The previous configurations have been completed , An error occurs when the command console is running , The error is shown below :( Explain , I use the Huawei cloud elastic server to connect to the database on the local virtual machine )
Problem related code , Do not paste screenshots
java The code is as follows :
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"; // User name and password of database , It needs to be based on your own settings static final String USER = "dbuser";static final String PASS = "Gauss#3demo"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try{ // register JDBC drive Class.forName(JDBC_DRIVER); // Open the link System.out.println(" Connect to database ..."); conn = DriverManager.getConnection(DB_URL,USER,PASS); // Execute the query System.out.println(" Instantiation Statement object ..."); stmt = conn.createStatement(); String sql; sql = "SELECT id, name, url FROM demo.websites"; ResultSet rs = stmt.executeQuery(sql); // Expand the result set database while(rs.next()){ // Retrieve... By fields int id = rs.getInt("id"); String name = rs.getString("name"); String url = rs.getString("url"); // Output data System.out.print("ID: " + id); System.out.print(", Site name : " + name); System.out.print(", Site URL: " + url); System.out.print("\n"); } // Close... When done rs.close(); stmt.close(); conn.close(); }catch(SQLException se){ // Handle JDBC error se.printStackTrace(); }catch(Exception e){ // Handle Class.forName error e.printStackTrace(); }finally{ // close resource try{ if(stmt!=null) stmt.close(); }catch(SQLException se2){ }// Don't do anything? try{ if(conn!=null) conn.close(); }catch(SQLException se){ se.printStackTrace(); } } System.out.println("Goodbye!");}
}
( All the above are copied, pasted and modified according to the parameters of Huawei ECs )
Operation results and error reporting contents
From the command desk javac -encoding utf-8 -cp d:\Download\postgresql.jar openGaussDemo.java
and java -cp .;D:/Download/postgresql.jar openGaussDemo Error after command :
The general meaning is either hostname Error or port number error , But it has been repeatedly checked that there is nothing wrong , Then it could be the back postmaster Don't accept TCP/IP The connection of , But they all press teacher Given the document , And it has been run successfully before , I don't know what went wrong .
My solution ideas and tried methods
I searched the Internet for a lot of relevant information , Try to pass the firewall , I also tried to restart the virtual database , Some parameters are configured , I looked at the listening address * you 're right , The remote connection permission is also granted to my dbuser user , All failed , Others said that they would be in win+R After input services.msc Turn on postgresql service , After a look, I found that there was no such service in my computer .
What I want to achieve
I just want to get through this java Program ,ball ball With all of you help help Small ! You can't finish it !
边栏推荐
- PHP uses the header function to download files
- English grammar_ Frequency adverb
- Video playback has repeatedly broken 1000w+, how to use the second dimension to create a popular model in Kwai
- Microservice practice based on rustlang
- Panel data set of rural cities and towns: per capita consumption and expenditure of prefecture level cities 2012-2019 & rural data of provinces 2013-2019
- Spark Foundation
- Simulink代码生成: 简单状态机及其代码
- Part II. S3. intuitionistic fuzzy multi-attribute decision-making method when attribute weight is intuitionistic fuzzy number
- [JVM Series 5] JVM tuning instance
- [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
Complex network analysis capability based on graph database
The most complete ongdb and neo4j resource portal in history
[azure data platform] ETL tool (6) -- re understanding azure data factory
Use cypher to get the tree of the specified structure
Alibaba cloud OSS access notes
MySQL learning summary 6: data type, integer, floating point number, fixed-point number, text string, binary string
[azure data platform] ETL tool (3) - azure data factory copy from local data source to azure
Azure SQL db/dw series (14) -- using query store (3) -- common scenarios
[azure data platform] ETL tool (2) -- azure data factory "copy data" tool (cloud copy)
随机推荐
Patrick Pichette, partner of inovia, former chief financial officer of Google and current chairman of twitter, joined the board of directors of neo4j
[azure data platform] ETL tool (6) -- re understanding azure data factory
English语法_频率副词
MySQL and PostgreSQL installation subtotal
MySQL learning summary XIII: detailed explanation of if, case, loop, while & cursor of process control
On the career crisis of programmers at the age of 35
Application scenarios of large arrows in Scala
测试写入mysql数据300W条,每次1.6-2W之间就断掉然后出现以下问题:
[azure data platform] ETL tool (7) - detailed explanation of ADF copy data
Data of all bank outlets in 356 cities nationwide (as of February 13, 2022)
Polymorphism in golang
China Civil Aviation Statistical Yearbook (1996-2020)
C语言程序设计——从键盘任意输入一个字符串,计算其实际字符个数并打印输出,要求不能使用字符串处理函数strlen(),使用自定义子函数Mystrlen()实现计算字符个数的功能。
PHP import classes in namespace
A data modeling optimization solution for graph data super nodes
Use PHP to count command line calls on your computer
MySQL learning summary Xi: detailed explanation of the use of stored procedures and stored functions
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)
Differences of several query methods in PDO
Rustup installation