所以我試圖連接到我的數據庫並顯示錶中的項目。 我得到的錯誤是:SQL異常:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:拒絕訪問用戶「鮑勃」 @「%」到數據庫「test」Java數據庫mySQL訪問被拒絕
這是正確的連接,如果那麼憑證是錯誤的錯誤?如果他們錯了,它是如何連接的?謝謝
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://THISISTHEHOSTNAME";
String username = "Bob";
String password = "password";
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = null;
ResultSet rs = null;
//SQL query command
String SQL = "SELECT * FROM TEST";
stmt = connection.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next())
{
System.out.println(rs.getString("ProductName") + " : " + rs.getString("UnitPrice"));
}
}
catch (SQLException e)
{
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE)
{
System.out.println("Class Not Found Exception: "+ cE.toString());
}
是的,它是連接,但它沒有登錄,因爲憑據是錯誤的。 –