I have problem with connecting my Maven web project to MySQL database in Netbeans. Every time when I am trying to connect it is throwing
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/Store
I have added mysql-connector-java version 5.1.38 dependency to pom.xml file. Then I have added mysql-connector-java-5.1.38-bin.jar to $CATALINA_HOME /lib folder. The folder WEB-INF/lib contains same .jar file. If I am trying to do
Class.forName("com.mysql.jdbc.Driver");
my project is connecting to DB without any exceptions.
Below my Servlet method connects to MySQL database
public void connectToDB(){
try{
String URL = "jdbc:mysql://localhost:3306/Store";
String username = "root";
String password = "sesame";
Connection connection = DriverManager.getConnection(URL, username, password);
System.out.println("DB has been connected!!!!!!!!!!!!!!!!!!");
}catch(SQLException ex){
for(Throwable t : ex){
t.printStackTrace();
}
}
}
The URL variable (port number and hostname) is correct. The problem is JDBC driver wasn't autoloaded at all.
I have searched through most of questions here but didn't find anything helpful.