我正在尝试连接我们正在托管的mysql数据库。我们已经安装了phpmyadmin,我们可以轻松访问数据库,并从那里获取内容。 (http://ipadress:port/phpmyadmin)
问题在于我们不断变得沟通失败。这是我的Java代码:
public static void main(String[] args) {
Connection conn;
Statement st;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://ipadress/Database", "user", "password");
st = conn.createStatement();
String query = "SELECT * FROM adres";
assert st != null;
rs = st.executeQuery(query);
System.out.println("Records from Database");
while (rs.next()) {
String straat = rs.getString("straat");
String huisnummer = rs.getString("huisnummer");
System.out.println("Straat: " + straat + "\nHuisnummer: " + huisnummer);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
我也尝试将它添加到mysql工作台但我一直得到同样的错误,所以我猜它不是代码方面的。这背后的原因是什么?因为我使用phpmyadmin连接它没有问题。
谢谢!
编辑: 错误消息
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.