I'm using properties file for Database,and here is mycode:
And I have set my database.prperties file in straight src
folder.
here is my code(I'm applying this code in a jsp page):
Properties prop=new Properties();
InputStream inputStream=null;
try{
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("database.properties");
prop.load(inputStream);
}
finally{
if (inputStream != null) try { inputStream.close(); } catch (IOException ignore) {}
}
String driver=prop.getProperty("driver");
if (driver != null)
{
System.setProperty("driver", driver);
}
String url = prop.getProperty("url");
String username= prop.getProperty("username");
String password = prop.getProperty("password");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,username,password); // Getting error at this line.
Statement stmt = con.createStatement();
String sql = "select * from info;";
ResultSet rs = stmt.executeQuery(sql);
System.out.println(sql);
Here is my properties file :
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/abc
username=crips
password=drift
But I'm getting this error java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)
at line Connection con = DriverManager.getConnection(url,username,password);
Any inputs on this context will appreciated.