So I've looked up a lot of different videos / tutorials. I've read through the MySQL connector J installation guide.. and I am still super confused!
I used the MySQL Installer to install all of the MySQL products.
Here is a pic of the installation. This displays that connector J is installed, and its current location.
So I read that I need to 'set the classpath' -- these words literally haunt me at night x_x.. but it seems like something that really shouldn't be difficult. I went to my environment variables and noticed right away that there is nothing there currently called CLASSPATH or classpath or Classpath.. you get it. It's not there. So I created one, but I am positive that it's not right, or that is not what my problem is. Heres a pic: pic of current classpath
I've seen in a lot of videos that they say I 'must' download different external tools to get it to work, but that doesn't make sense to me, and the MySQL installation guide doesn't ever mention that, plus those videos are all possibly out dated.
I attempted to run this code:
import java.sql.*;
public class Main {
private static String connectionString = "jdbc:mysql://localhost:3306/test";
private static Connection connection;
private static Statement command;
private static ResultSet data;
public static void main(String[] args) {
// launch(args);
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionString);
command = connection.createStatement();
command.execute("INSERT INTO accounts VALUES (default, 'test1', 'password1', 2018-12-18)");
} catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
System.out.println("cnfe was thrown");
}catch(SQLException sqlE) {
sqlE.printStackTrace();
}
}
}
That returned two separate errors:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.tjp.Main.main(Main.java:31)
2 -- this one occurs without the "forName" method.
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.tjp.Main.main(Main.java:33)
Any help will be greatly appreciated!! Thank you so much