Yu Sasaki's Blog

Icon

プログラミングとか英語とかの練習!

JDBC – using mysql driver on Mac

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!

Advertisements

Filed under: EJB605, Java

One Response

  1. […] I created a “Student table” last time, and today I learned how to make a connection on […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: