I'm trying to write a sample jdbc program to connect to mysql db which is in the remote machine
// JDBC driver name and database URL
String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://<remote machine>/<database>"
// Database credentials
String USER = "root";
String PASS = "mnlinux";
Class.forName(JDBC_DRIVER);
Connection con = DriverManager.getConnection(DB_URL, USER, PASS);
Statement stmt = con.createStatement();
String sql = "SELECT x FROM t";
ResultSet resultSet = stmt.executeQuery(sql);
while(resultSet.next()){
//Retrieve by column name
int id = resultSet.getInt("x");
//Display values
System.out.print("ID: " + id);
}
resultSet.close();
stmt.close();
con.close();
*Its returning Exception in thread "main" java.sql.SQLException: Access denied for user 'root'@'CurrentMachine' (using password: YES)*
while executing DriverManager.getConnection(DB_URL, USER, PASS);
Please help me to connect to the db. My MySQL is up & running. Both dbserver & currentmachine are in same network (i'm able ping).
Thanks in advance.
Allow full access to database from any ip OR replace % with your IP from where do you want to access database and try.