Java Reference
In-Depth Information
Connection conn = DriverManager.getConnection(url, username, password);
Getting this to compile and run requires you to have the appropriate
JDBC JAR files available. For Oracle, see your Oracle DBA, or see pages
228-229 of
Java Oracle Database Development
by David Gallardo. For MySQL,
it's an easy download you can install from the Internet.
15.3.1
The JDBC implementation for MySQL is available for free from
http://www.mysql.com/downloads/api-jdbc.html
.
The current version at the time of writing was
mysql-connector-java-
3.0.9-stable.tar.gz
which you can unpack as follows:
Downloading JDBC for MySQL
$ gunzip mysql-connector-java-3.0.9-stable.tar.gz
$ tar xvf mysql-connector-java-3.0.9-stable.tar
That leaves you with a directory named
mysql-connector-java-
3.0.9-stable
which contains a JAR file named
mysql-connector-java-
3.0.9-stable-bin.jar
along with some directories (which are the contents
of the JAR, unpacked) and a few miscellaneous files.
From the readme file:
Once you have unarchived the distribution archive, you can install the
driver in one of two ways:
• Either copy the
com
and
org
subdirectories and all of their contents
to anywhere you like, and put the directory holding the
com
and
org
subdirectories in your classpath, or
• Put
mysql-connector-java-3.0.9-stable-bin.jar
in your class-
path, either by adding the
full
path to it to your
CLASSPATH
environment variable, or putting it in
$JAVA_HOME/jre/lib/ext
.
Unlike JUnit, it is OK to put this JAR in the
ext
directory.
15.4
Q
UERYING
D
ATA
Back to our example. Do you remember the portion that built the query? Here
it is again: