当前位置:网站首页>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 )

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 :

img


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 !

原网站

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206061224173708.html

随机推荐