13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

332Chapter 15Accessing the Data: An Introducti<strong>on</strong> to JDBCC<strong>on</strong>necti<strong>on</strong> c<strong>on</strong>n = DriverManager.getC<strong>on</strong>necti<strong>on</strong>(url, username, password);Getting this to compile and run requires you to have the appropriateJDBC JAR files available. For Oracle, see your Oracle DBA, or see pages228–229 of Java Oracle Database <str<strong>on</strong>g>Development</str<strong>on</strong>g> by David Gallardo. For MySQL,it’s an easy download you can install from the Internet.15.3.1 Downloading JDBC for MySQLThe JDBC implementati<strong>on</strong> for MySQL is available for free fromhttp://www.mysql.com/downloads/api-jdbc.html.The current versi<strong>on</strong> at the time of writing was mysql-c<strong>on</strong>nector-java-3.0.9-stable.tar.gz which you can unpack as follows:$ gunzip mysql-c<strong>on</strong>nector-java-3.0.9-stable.tar.gz$ tar xvf mysql-c<strong>on</strong>nector-java-3.0.9-stable.tarThat leaves you with a directory named mysql-c<strong>on</strong>nector-java-3.0.9-stable which c<strong>on</strong>tains a JAR file named mysql-c<strong>on</strong>nector-java-3.0.9-stable-bin.jar al<strong>on</strong>g with some directories (which are the c<strong>on</strong>tentsof the JAR, unpacked) and a few miscellaneous files.From the readme file:Once you have unarchived the distributi<strong>on</strong> archive, you can install thedriver in <strong>on</strong>e of two ways:• Either copy the com and org subdirectories and all of their c<strong>on</strong>tentsto anywhere you like, and put the directory holding the com and orgsubdirectories in your classpath, or• Put mysql-c<strong>on</strong>nector-java-3.0.9-stable-bin.jar in your classpath,either by adding the full path to it to your CLASSPATHenvir<strong>on</strong>ment variable, or putting it in $JAVA_HOME/jre/lib/ext.Unlike JUnit, it is OK to put this JAR in the ext directory.15.4QUERYING DATABack to our example. Do you remember the porti<strong>on</strong> that built the query? Hereit is again:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!