Kristofer Mar Einarsson Kristofer Mar Einarsson - 1 month ago 14
MySQL Question

From local to global database

i have a problem, i want do create a "global database" which should be accessible from all computers anywhere but i can't find an solution. I have made an database with MAMP and myphpadmin and it's working fine on my computer only but when i try to login from other computers i get the message "java.sql.SQLException: Acces denied for user "rood@localhost" (using password: YES)". Can anyone please give help me go make my database global?

this is my code for the database connection, it is a login frame.

//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);

Answer

Your problem not in your codes, you need to create new user "(accessable from any machine)" on your database, look at the picture :

picture

because of your account only can access from localhost.

I hope this help you.Good Luck.