Tuesday, April 2, 2013

How to install and configure MySQL Connector/J to java

MySQL Connector is JDBC implementation for communicating with MySQL.

Test Environment

  • OS: Windows 7 64-bit
  • Java: 1.7
  • MySQL: 5.5

Installing Connector/J

  • Go to the MySQL Drivers page.
  • Click Download link next to "JDBC Driver for MySQL (Connector/J)".
  • You can download Connector/J package  either the compressed TAR archive or ZIP archive. Here I will show only the ZIP archive.
  • After download, save the zip file in the C:\Temp.
  • Extract ZIP file using any Zip file extractor tool such as 7-Zip, WinZip.
  • In my case, I save the output folder in "C:\MySQL Related\mysql-connector-java-version"

Configuring Driver & Connector/J CLASSPATH

  • Once you extract and save the output files in specific folder (see Installing Connector/J section), you set the CLASSPATH using environment variable or using -cp command.
  • Using Environment Variable:
    • Right click My Computer, click properties.
    • Click the advanced tab.
    • Click the Environment Variables button at the bottom of the tab.
    • Under user variables, add a new variable named "CLASSPATH".
    • Set "CLASSPATH" to "C:\Folder Path\mysql-connectorjava-
    • version-bin.jar" and click "OK".
    • Click "OK" in "Environment Variables" and "System Properties" windows.

No comments: