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.
我是第一次尝试,因为我对网站主办完全不熟悉所以请提前帮助我!
答案 0 :(得分:0)
在您的本地或服务器
上相同Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://DomainName OR IP:3306/databasename", "username", "password");
答案 1 :(得分:0)
在000webhost.com上,出于安全性和服务器性能原因,远程MySQL连接被禁用。 如果您升级帐户,将启用MySQL连接。