i have an problem with my java program i'm trying to connect to an MYSQL database but it says driver not found i've imported mysql-connector-java into the project even with output set so it exports with the program
the class:
package com.CloudyProductions.GCDSS;
import java.sql.*;
public class mysql {
public static Connection c;
static String host = "localhost";
static String port = "3306";
static String database = "";
static String username = "root";
static String password = "";
public static void connect() {
try {
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I've added the mysql-connector to the project via maven and did what you said but now get this error:
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)