Outline: Wendy Liu CSC309F - Fall 2007
Outline: Wendy Liu CSC309F - Fall 2007
1 2
Java Persistence
JDBC (Java Database Relational Database
Connectivity) Management System
Object relational (RDBMS)
Persistence via Database mapping Object-oriented
Java Data Object Database Management
(JDO) System (OODBMS)
Enterprise JavaBean
(EJB)
3 4
5 6
1
Relational Database Movie Database Example
First published by Edgar F. Codd in 1970
A relational database consists of a collection
showtimes
of tables showtimeid movieid theaterid sdate stime available
1 1 1 3/20/2005 20:00:00 90
7 8
RDBMS Technology
Client/Server Databases
Derby, Oracle, Sybase, MySQL, PointBase,
SQLServer JDBC
Embedded Databases (Java DataBase Connectivity)
Derby, PointBase
Personal Databases
Access
9 10
http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
11 12
2
Components of JDBC Architecture - 1 Components of JDBC Architecture - 2
Java application JDBC Driver
In need to access database Translates API calls to requests made against the
Uses the API specific database
Specific driver required for the chosen database
JDBC API
Installed on the client. Usually a set of class files
Provides DB independent abstraction to
placed in the class path
Establish a connection with a database
Send SQL statements All large databases are now supported
13 14
v3.0
v4.0
(May incur different class names in the Derby drivers)
15 16
Statement
For SQL statements
public Connection getConnection(String username,
executeQuery(), executeUpdate() String password)
PreparedStatement
Precompiled SQL statement; more efficient for multiple executions Attempts to establish a connection with the data source
executeQuery(), executeUpdate(), setInt(), setString() that this DataSource object represents using the given
Parameter index starts from 1
ResultSet username and password
next()
Accessing next row
getString(), getInt()
Retrieving attribute values
17 18
3
Derby Example 1: Connection Executing a Query
import org.apache.derby.jdbc.EmbeddedDataSource; java.sql
import javax.sql.DataSource;
PreparedStatement
import java.sql.*; Precompiled SQL statement; more efficient for multiple executions
… executeQuery(), executeUpdate(), setInt(), setString()
// Driver code Parameter index starts from 1
EmbeddedDataSource eds = new EmbeddedDataSource(); Statement
eds.setDatabaseName(dbname); executeQuery(), executeUpdate()
eds.setCreateDatabase("create");
ResultSet
…
next()
// JDBC code Accessing next row
Connection con = eds.getConnection(); getString(), getInt()
Retrieving attribute values
19 20
Executing Update
int rowsAffected =
stmt.executeUpdate(
"DELETE * FROM ACCOUNTS;");
Executes SQL INSERT, UPDATE, or Announcements
DELETE statements
Returns the number of rows affected
23 24
4
Midterm Important Announcement (Repeat)
Topics covered Tuesday Oct 16, 2007
Lectures 1-9 inclusive 2-hr tutorial given in a CDF lab, BA3185
From XHTML to Java Servlets and JSP
Thursday Oct 18, 2007
Use lecture notes as a guideline
Midterm, BA2195
You can bring only 1 page cheat-sheet
Letter
size
Starting Tuesday Oct 23, 2007
The official lecture room will be BA2185 on each
Double sided
Tuesday until the end of term
Format similar to previous years
No change to Thursdays’ classes (BA1240)
Short conceptual questions ~40%
Programming questions ~60%
25 26