22JDBC - CS108 Stanford Winter 2012 Handout#22 Young JDBC...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS108, Stanford Handout #22 Winter 2012 Young JDBC JDBC allows us to connect our Java programs to a database. The MySQL JDBC Driver JDBC can work with a variety of different types of databases. A JDBC Driver connects Java to a particular type of database. In our case, we’ll need a JDBC driver for MySQL. We will use the Connector/J driver from MySQL.com available at: http://www.mysql.com/products/connector/ Download the driver. The download will be a zip file including Java source code and a JAR file with the source pre-compiled. Ignore the source code, we are only interested in the JAR file. Go ahead and store the mysql-connector-java-5.1.18-bin.jar file somewhere handy. When creating a project which uses JDBC you’ll need to tell Eclipse where your JDBC driver is. You can do this by right-clicking on the project folder in Eclipse and select “Properties”. This will bring up the project’s properties window, switch to the “Java Build Path” section and select the “Libraries” tab:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Click on the “Add External JARs” button on the right side of the window. Find and add the mysql-connector-java-5.1.18-bin.jar file. A Simple JDBC Program When working with JDBC we’ll need the same pieces of information we needed when working with MySQL directly. Make sure you have the following information which you should have received via e-mail: Your MySQL Username Your MySQL Initial Password The name of the Stanford MySQL Database Server Your MySQL Database Name In the previous handout on MySQL we created a table of metropolises and stored it in our MySQL database. We will now take a look at a program which accesses that table. Just as a reminder, here is what the table looked like: +---------------+---------------+------------+ | metropolis | continent | population | +---------------+---------------+------------+ | Mumbai | Asia | 20400000 | | New York | North America | 21295000 | | San Francisco | North America | 5780000 | | London | Europe | 8580000 | | Rome | Europe | 2715000 | | Melbourne | Australia | 3900000 | | San Jose
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2012 for the course CS 108 taught by Professor Jimenez during the Winter '08 term at Stanford.

Page1 / 6

22JDBC - CS108 Stanford Winter 2012 Handout#22 Young JDBC...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online