gpt4 book ai didi

java - 无法连接到我的数据库 000webhost.com

转载 作者:行者123 更新时间:2023-11-30 23:15:41 25 4
gpt4 key购买 nike

  try {
String connectionURL = "jdbc:mysql://sql4.000webhost.com/a7291194_xxx";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "a7291194_xxx", "xxx");
if(!connection.isClosed())
System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}catch(Exception ex){
System.out.println("Unable to connect to database"+ex);
}

我尝试使用以下连接器代码连接 000webhost.com 上的数据库,但它给我一个错误:

    CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.

我是第一次尝试我最好的,因为我是虚拟主机的新手所以请帮助我提前谢谢!

最佳答案

无论是在你的本地还是在服务器上都是一样的

Class.forName("com.mysql.jdbc.Driver");  
Connection connection = DriverManager.getConnection("jdbc:mysql://DomainName OR IP:3306/databasename", "username", "password");

关于java - 无法连接到我的数据库 000webhost.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17969106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com