Connecting to mySQL using Maven

admin

Administrator
Staff member
I am trying to connect to a MySQL Database using the mysql-connector-jar, which gets imported via maven. I have the dependency in the POM file as follows:

Code:
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.38</version>
</dependency>

And I initialize my connection with the code below:

Code:
String dbUrl = "jdbc:mysql:host";
String dbClass = "com.mysql.jdbc.Driver";
String query = "update aem_assets set path = (?), assetid = (?), filename = (?), cadid = (?) where id = (?)";
try {
    Class.forName(dbClass).newInstance();

However, I keep getting
Code:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found
. I am trying to avoid manually adding the jar to the build path since my company uses maven for builds and we want this tool to be run from multiple instances without having to add jars.

I have also tried it without the
Code:
newInstance()
method.

I am referencing this article for implementation: <a href="https://dimitrisli.wordpress.com/2010/08/06/jdbc-mysql-maven-working-example/" rel="nofollow noreferrer">https://dimitrisli.wordpress.com/2010/08/06/jdbc-mysql-maven-working-example/</a>

Edit: I have added the JAR file to the module dependency. <a href=" " rel="nofollow noreferrer"><img src=" " alt="enter image description here"></a>

However it is STILL giving me the error. Am I missing something?