Once you have extracted the distribution archive, you can
install the driver by placing
mysql-connector-java-in your classpath, either by adding the full path to
it to your version-bin.jar
CLASSPATH environment variable, or
by directly specifying it with the command line switch
-cp when starting the JVM.
To use the driver with the JDBC
DriverManager, use
com.mysql.jdbc.Driver as the class that
implements java.sql.Driver.
You can set the CLASSPATH environment
variable under Unix, Linux or Mac OS X either locally for a user
within their .profile,
.login or other login file. You can also set
it globally by editing the global
/etc/profile file.
For example, add the Connector/J driver to your
CLASSPATH using one of the following forms,
depending on your command shell:
# Bourne-compatible shell (sh, ksh, bash, zsh): shell> export CLASSPATH=/path/mysql-connector-java-ver-bin.jar:$CLASSPATH # C shell (csh, tcsh): shell> setenv CLASSPATH /path/mysql-connector-java-ver-bin.jar:$CLASSPATH
Within Windows 2000, Windows XP, Windows Server 2003 and Windows Vista, you set the environment variable through the System Control Panel.
To use MySQL Connector/J with an application server such as
GlassFish, Tomcat or JBoss, read your vendor's documentation for
more information on how to configure third-party class
libraries, as most application servers ignore the
CLASSPATH environment variable. For
configuration examples for some J2EE application servers, see
Section 22.3.7, “Connection Pooling with Connector/J”
Section 22.3.8, “Load Balancing with Connector/J”,
and
Section 22.3.9, “Failover with Connector/J”.
However, the authoritative source for JDBC connection pool
configuration information for your particular application server
is the documentation for that application server.
If you are developing servlets or JSPs, and your application
server is J2EE-compliant, you can put the driver's
.jar file in the
WEB-INF/lib subdirectory of your webapp, as
this is a standard location for third party class libraries in
J2EE web applications.
You can also use the MysqlDataSource or
MysqlConnectionPoolDataSource classes in
the com.mysql.jdbc.jdbc2.optional package, if
your J2EE application server supports or requires them. Starting
with Connector/J 5.0.0, the
javax.sql.XADataSource interface is
implemented using the
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
class, which supports XA distributed transactions when used in
combination with MySQL server version 5.0.
The various MysqlDataSource classes
support the following parameters (through standard set
mutators):
user
password
serverName (see the previous section
about fail-over hosts)
databaseName
port

User Comments
For JDK releases, I found a way to get it working by placing the .jar into the %insertPathToJava%/jre/lib/ext/. I tried this with 1.6.0u2 on XP and the program began compiling, without the class path workaround.
Copying the connector jar into your Java installation does work, but is not ideal because it will probably break if you install a java update (since that installs a whole new VM).
If you don't want to mess around with CLASSPATH, you could always include the code directly with your application; the 'unjar' Ant task is useful for this. Create a target which unjars library classes into your build tree before your jar/war target, and you'll be all done.
For Mac OS X, it seems that copying the MySQL driver .jar file into /Library/Java/Extensions is the only thing to do.
What finally worked for me, I was trying to get OpenOffice to connect to MySQL DB, was to place a symbolic link in the jre1.6.0_17/lib/ext/ directory.
On Linux, untar or unzip, mysql-connector-java-5.0.X any where on the system, I used /usr/java. I then created a symbolic link 'ln -s /usr/java/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar /usr/java/latest/lib/ext/'. Once OpenOffice was pointed to the currect version of java, everything worked.
The trick for me was learning about the extensions directory. In this case /usr/java/jre1.6.0_17/lib/ext/.
For Mac OS X, I was getting 'Driver not suitable' exception. I've noticed the extracted jar file permissions were set to 655 and should be 755 which has fixed the problem for me.
In addition to altering the CLASSPATH if you are using Windows 7 or above during the installation of the JConnnector to MySQL, insure the UNBLOCK button at the bottom of the properties dialog box is clicked while coping the correct path for ue. Find the file, then copy and paste it's location during this process locate the Advance button underneath lies the UNBLOCK button. By default the file usage is blocked due to the security elements involved. It will state "this file is from another computer" therefore it's in a blocked state after installation. The .jar file and the MySQL JConnector file are in this state. This will cause the code or functions not to return the desired response if not unblocked.
Add your own comment.