BAD ANSWER - Old
I figured it out.
I opened the jar file in 7zip, dragged out the com folder and put it in my lab folder.
Works!!
GOOD ANSWER - VSCode - New
- Download Java Extension for VSCode.
- Go to Command Pallet (ctrl+shift+P.) and write Create Java
Project.
- Click on Build Tools
- Name it whatever your project's name is.
- Drag/Drop your Java files into the folder "src" in the project's folder.
- Look at the bottom left of your screen where it says Java Projects and expand it.
- Hover on the right side of Referenced Libraries and click the + button.
- In the popped up Open window find where you have Connector/J and select the .jar file (in this case, mysql-connector-java-8.0.28.jar) and click Select Jar
Libraries
- Click the Refresh button on your Java Project and click Build Workspace and pick Full
- Restart VSCode
- Click the Run and Debug button / Press ctrl+shift+D
- Works!
GOOD ANSWER - Command Line - New
javac -classpath "[Project folder or just a "." if your console is in it];[folder with jarfile]\\[jarfile].jar" Program.java
java -classpath "[Project folder or just a "." if your console is in it] ; [folder with jarfile]\\[jarfile].jar" Program
In this specific case
javac -classpath ".;C:\\Program Files\\MySQL\\Connector J 8.0\\mysql-connector-java-8.0.28.jar" Program.java
java -classpath ".;C:\\Program Files\\MySQL\\Connector J 8.0\\mysql-connector-java-8.0.28.jar" Program
So in the background the VSCode Answer does what the Command Line Answer does.
Basically every time you run java or javac, java adds a thing implicitly pointing/referencing where your classes (compiled .java programs) are (in a folder, or a zipped folder called a .jar), to your java/javac commands called a classpath in between the java/javac and your .java file.
With the implicit
javac Program.java
java Program
Being equivalent to
javac -classpath "." Program.java
java -classpath "." Program
The implicity makes sense as you would be using the classes from the folder that the program is in. (Note: The "." means the folder the Commandline is in, navigated by cd/ChangeDirectory in Bash/PowerShell, see Linux/Mac/Unix Path Formats and/or Windows Path Formats ).
Now you might be wondering why there's a ";", this is to denote multiple classpaths, as you want to look into your projects, ".", and the library JDBC, if you wanted to add more classpaths add another ";", however on Linux/Mac/Unix you would add ":" instead of ";".
The reason the old Bad Answer worked was because the dragged folder was included in the implicit classpath.
The reason the old Bad Answer is a bad answer is because its reflective of poor practices and lack of understanding. Its poor practice for few reasons: the zipped files take up less space thus unzipping needlessly eats space, these files aren't yours so mixing them with yours could violate the terms of use of the author, and its a lot of work unzipping that you're doing for no reason.