The JDBC JAR belongs in the Tomcat /lib folder. From these docs:
It means that only libraries visible to the listener such as the ones
in $CATALINA_BASE/lib will be scanned for database drivers.
Your database URL is wrong, too. Look at the docs again. Your URL is:
mysql.jdbc://localhost/ticketdb1
It should be:
jdbc:mysql://localhost/ticketdb1
You aren't using root access for your application, are you? That's lazy and dangerous. Create a new user for your app and GRANT appropriate permissions.
This class connects to MySQL running on my machine. It gives some interesting messages that you'll find helpful. Take note of the JAR version and the driver class name.
package database;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
* Database utilities
* Created by Michael
* Creation date 5/3/2016.
* @link https://stackoverflow.com/questions/36999860/mysql-driver-problems/37000276#comment61553720_37000276
*/
public class DatabaseUtils {
public static final String DEFAULT_DRIVER = "com.mysql.cj.jdbc.Driver";
public static final String DEFAULT_URL = "jdbc:mysql://localhost/world";
public static final String DEFAULT_USERNAME = "root";
public static final String DEFAULT_PASSWORD = "xxx";
public static void main(String[] args) {
Connection connection = null;
try (connection = createConnection(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD)) {
DatabaseMetaData meta = connection.getMetaData();
System.out.println(String.format("Connected to %s version %s", meta.getDatabaseProductName(), meta.getDatabaseProductVersion()));
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
public static Connection createConnection(String driverClass, String url, String username, String password) throws ClassNotFoundException, SQLException {
Class.forName(driverClass);
return DriverManager.getConnection(url, username, password);
}
public static void close(Connection connection) {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
I use JDK 8 and this dependency in my pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.2</version>
</dependency>
Here's the output I got:
Tue May 03 05:48:30 EDT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Connected to MySQL version 5.7.11-log