I have some trouble connecting my remote mysql database from my rest web service running on Tomcat. I know this is common issue but I tried every way that I found on the internet. Error is: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
in here: Class.forName("com.mysql.jdbc.Driver");
I am using Intellij, what I tried is, I added "mysql-connector-java-5.1.46-bin.jar" and "mysql-connector-java-5.1.46.jar" to my project as library in project structure tab of IntelliJ and I also put these files to resources folder which I marked as resources file from project structure tab. I can see these to jar file in external libraries. I added these to jar file to .classpath file and in the artifacts tab of project structure I added them as library and also as extracted directory.
But no result, same error again. Where am I doing wrong?
Edit: I am adding whole related code. I realized that if I try to run this code below in an other class that not related with rest web service and tomcat, it works. But when I try it on tomcat, It does not work.
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://(ip):3306/DatabaseName",
"(username)","password");
statement = connection.createStatement();
}catch (SQLException e){
e.printStackTrace();
}catch (ClassNotFoundException e){
e.printStackTrace();
}