Today I learned how to interact with JDBC.
Tasks were :
- Create a table called “Students” onto mysql database in my zenit account
- Insert Students data into the table
At first time, I had a problem with importing the mysql driver.
I needed to set up a CLASSPATH environment variable so that the Java compiler can make use of the driver wherever it’s placed, but I had no idea how to set up classpath on my Mac. After googling, I found out some ways to set up CLASSPATH on Mac, and the easiest way that I figured out is this: putting the following line in my .bashrc file.
export CLASSPATH=/Library/Java/Extensions/mysql-connector-java-3.1.8-bin.jar;
Now that my Java compiler knows where to get the actual mysql driver class by CLASSPATH keyword, I am able to compile my Java program with the following simple command.
javac -cp CLASSPATH -d classes db/*.java
If I don’t use CLASSPATH, I have to use the following long command.
javac -cp /Library/Java/Extensions/mysql-connector-java-3.1.8-bin.jar -d classes db/*.java
See you!
Posted in EJB605, Java Image may be NSFW.
Clik here to view.

Clik here to view.
