0
我有一個問題,我想創建一個「全局數據庫」,應該可以從任何地方的所有計算機訪問,但我找不到解決方案。我使用MAMP和phpMyAdmin創建了一個數據庫,並且它只能在我的計算機上正常工作,但是當我嘗試從其他計算機登錄時,我收到消息「java.sql.SQLException:Acces denied for user」rood @ localhost「(使用密碼:是)」。從本地到全局數據庫
這是我的數據庫連接代碼,它是一個登錄框架。
//Login button
JButton btnNewButton = new JButton("Login");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
try {
// connection to databse
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/myusers", "root", "root");
String query = "select * from brugere where username=? and password=?";
PreparedStatement myStnt = myConn.prepareStatement(query);
myStnt.setString(1, textField.getText());
myStnt.setString(2, passwordField.getText());
//// Create statement
ResultSet myRs = myStnt.executeQuery();
//
int count = 0;
while (myRs.next()) {
count = count + 1;
}
if (count == 1) {
myRs.close();
myStnt.close();
myConn.close();
MainMenu mm = new MainMenu();
mm.setVisible(true);
frame.dispose();
frame.dispose();
}
else if (count > 1)
{
JOptionPane.showMessageDialog(null, "Duplicate Username and password");
}
else
{
JOptionPane.showMessageDialog(null, "Sorry wrong username or password");
}
}catch (Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
});
btnNewButton.setBounds(288, 96, 89, 67);
frame.getContentPane().add(btnNewButton);