Lab on JDBC
PART 1 – Query, Update and Insert records (get existing programs to work)
1) DOWNLOAD JDBC DRIVER FOR ORACLE
Example: download the ojdbc14.jar (JDBC Driver) from
and place it in the ext sub-directory of your java environment
c:\Program Files\Java\jdk1.6.0\jre\lib\ext\ folder.
You may find this file in your hard drive. If so, move it to the sub-directory described above.
(Obs.: you may also download this file from my
2) Create a directory called labJava directory on your hard disk
3) DOWNLOAD SAMPLE PROGRAMS
download the files query.java, insert.java and update.java to the labJava directory. Also download
query.bat, insert.bat and update.bat
to your this labJava directory.
4) Open a DOS Window (Programs->Acessories-> Command Prompt), go to the labjava
directory (cd \LabJava) and Type in Query, then Insert and Update from the dos prompt to
compile and run your three programs respectively. Note that you have to change the connection
string to correspond to the username and password of the table you are accessing. If not in
CL2009, you may also have to change the host name or instance name.
If your have trouble executing the lab
5) Make sure that the parameters in the connection string of your Java program are correct.
In the example below, jdbc:oracle:thin is informing the type of jdbc driver you are using. The
options are thin jdbc:oracle:thin Or
localhost means that the DB you are accessing is the Oracle DB on your local harddrive. 15210 is
the host name. You can find it by verifying the file tnsnames.ora or listener.ora or by SELECT
host_name FROM v$instance;. Xe is the instance name. you can find it with the command
SELECT Instance_name FROM v$instance; To query the view V$INSTANCE, the user
must have dba privileges. The last two parameters above is the username and password. In the
example the user name and password are both csis3310.
6) If you were unable to connect to your database, make sure that you have your tables and that
The tables are under the same user that the connection string is indicating. For example, on the
connection string above, the user is csis3310 and the password is also csis3310.
If your table doesn’t exist, Create the customers table under the user name you are working on or
change the user name in the connection string.
http://science.kennesaw.edu/~mguimara/8080/insert.sql if you haven’t
done so yet (from previous lab).. Modify the query, insert and update (java and batch files) to be
able to work with another attribute or another table (see instructor).
7) Deliverables snapshots of your query returning data, your program modifying data, and
List the Create a java program that lists the products in descending order by price.
Deliverables: show your program listing all products in descending order.