I'm creating a web app using servlets and Tomcat in IntelliJ. I want to connect my application to a MySQL database with JDBC. I downloaded MySQL Workbench, connected to it, and created a database.
Now, in my IntelliJ project I followed this tutorial to add database connection, and my properties look like this:
My mysql driver version is 5.1.35, so it should be compatible with JDBC 4.0. As found out (mainly here) to connect with my database I should use just:
Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
However,when I try to connect I get No suitable driver
exception. Even when I add
Class.forName(DB_DRIVER).newInstance();
I end up with the same. It only works when I add manually jar to this driver in my libraries and artifacts:
Is it really the only way? If IntelliJ downloaded the jar automatically, shouldn't it also load it automatically when I try to connect? In DriverManager
documentation there is something like this: As part of its initialization, the DriverManager class will attempt to load the driver classes referenced in the "jdbc.drivers" system property.
Do I have to configure this property somehow?