I am trying to connect to MySQL using JDBC. I have one strange behavior if I passed the hardcode value for url, username and password to DriverManager.getConnection() the connection to database is OK. But if I passed argument as variable the connection to JDBC failed with below Error.
java.sql.SQLException: No suitable driver found for "jdbc:mysql://localhost:3306/hplus"
FileInputStream fis = new FileInputStream(path+"config.properties");
Properties prop = new Properties();
prop.load(fis);
String url = prop.getProperty("url");
String username = prop.getProperty("username");
String password = prop.getProperty("password");
System.out.println(url);
System.out.println(username);
System.out.println(password);
conn=DriverManager.getConnection(url, username, password);
//conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hplus","root","123Nbr@");;
}catch(Exception e) {
System.out.println(e);
}
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
"jdbc:mysql://localhost:3306/hplus"
"root"
"123Nbr@"
java.sql.SQLException: No suitable driver found for "jdbc:mysql://localhost:3306/hplus"