I am working on a mysql database, accessing from a Servlet program(through Eclipse) on Mac. My recent problem is, I couldn't access the mysql DB through my Servlet, which was working fine earlier. I use MySQLWorkBench, where the DB is running on Mac. When Servlet is trying to access it, it throws the below error. Actually, the password is empty. Working on Mac machine.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
Servlet code is below:
// MySQL
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", "root");
connectionProps.put("password", ""); // No password is set
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:" + "mysql" + "://" +
"localhost" +
":" + "3306" + "/InfoDB",
connectionProps);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Connected to database");
// insert record
try {
Statement stmt = (Statement) conn.createStatement();
String sql = "SELECT IP FROM InfoTable";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
String ipaddress = null;
while(rs.next()){
//Retrieve by column name
ipaddress = rs.getString("IP");
System.out.println("IP Address retrieved from DB: " + ipaddress);
}
PrintWriter out = response.getWriter();
out.println(ipaddress);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The same code was working fine earlier. I saw some suggestions here,
Solution for this issue ,
but i don't know where is this information.schema table
resides and how to set the permission.
And, another suggestion is there in this link, Solution for this issue But, i don't understand how to fix this way?
Could someone please guide me to fix this issue?