Core Java Advanced LiveLessons

Java Database Connectivity

Copyright © Cay S. Horstmann 2016

Understand the design of the Java database connectivity API

The JDBC API

Be able to connect to a database in a Java program

Requirements for Using JDBC

Connecting to the Database

lesson09/test

java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server start &
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. test.TestDB
java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server shutdown

Execute SQL statements from a Java program

Executing SQL Statements

Managing JDBC Objects

SQL Exceptions and Warnings

lesson09/query

java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server start &
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. exec.ExecSQL Authors.sql
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. exec.ExecSQL Publishers.sql
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. exec.ExecSQL Books.sql
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. exec.ExecSQL BooksAuthors.sql

java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. query.QueryTest
java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server shutdown

Use database query results

Result Sets

Prepared Statements

SQL Escapes

Retrieving Autogenerated Values

Multiple Results

Scrollable Result Sets

Scrolling and Updating Result Sets

Cached Row Sets

Group SQL statements into transactions and batches

Transactions

Batch Updates

Access database metadata

Metadata

Result Set Metadata

lesson09/query

java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server start &
java -classpath /opt/jdk1.8.0/db/lib/derbyrun.jar:. view.ViewDB
java -jar /opt/jdk1.8.0/db/lib/derbyrun.jar server shutdown