EDIT: Fixed the issue - I wasn't declaring the dependency within the apache tomcat plugin:
<extraDependencies>
<extraDependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.1.3.1</version>
</extraDependency>
<extraDependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</extraDependency>
<extraDependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</extraDependency>
</extraDependencies>
As well as being declared in the pom as seen below.
Question:
I'm trying to use the mysql jdbc driver in my maven project:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
But i'm getting:
java.lang.ClassNotFoundException: "com/mysql/jdbc/Driver";
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.ollynural.app.database.retrievedatabase.DatabaseAccessor.returnSummonerDTOFromDatabaseUsingName(DatabaseAccessor.java:53)
EDIT: Tried using the string instead of CLASS, and error is:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
And DatabaseAccessor returnSummonerDTOFromDatabaseUsingName is:
String URL = prop.getProperty("URL");
String USER = prop.getProperty("USER");
String PASS = prop.getProperty("PASS");
String CLASS = prop.getProperty("CLASS");
String TABLE_UNIVERSITY_INFO = prop.getProperty("TABLE_BASIC_INFO");
try {
Class.forName(CLASS);
} catch (ClassNotFoundException e) {
System.out.println("Can't find SQL Driver");
e.printStackTrace();
}
The properties are:
URL="jdbc:mysql://localhost:3306/league_database_schema";
USER="username";
PASS="password"
CLASS="com.mysql.jdbc.Driver";
The properties are getting to the class fine, but I have no idea why it can't find the class. I'm relatively new to maven, and this was working before i moved over to intellij and eclipse, but any help would be incredibly helpful!
Thank you
Class.forName("com.mysql.jdbc.Driver")? Looks rather strange, that the exception shows the full qualified name with slash. And can you use other libraries, which are added using maven? Just to be sure, that Maven and your build path are configured correctly.