Docsity

Java Database Connectivity: ODBC vs JDBC, Slides of Applications of Computer Sciences

Toggle sidebar
bg1
JDBC/ODBC Overview
Introduction to JDBC/ODBC
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d

Partial preview of the text

Download Java Database Connectivity: ODBC vs JDBC and more Slides Applications of Computer Sciences in PDF only on Docsity!

JDBC/ODBC Overview

Introduction to JDBC/ODBC

ODBC

  • ODBC (Open Database Connectivity) is an API

introduced by Microsoft that allows applications

to access databases by using SQL.

  • By using ODBC, a single application can access

remote databases under different DBMSs (i.e.,

Informix, Oracle, Sybase, etc.)

  • The idea behind ODBC is to have a single API to

interact with a database

  • However, there is a lot of work to be done in order

to get all operating systems to use ODBC, and that

may not be possible or even desirable given that

there is JDBC.

n -Tier Architectures

  • 1-tier
  • 2-tier
  • 3-tier

Database server (someone else’s C program)

Overview

  • Setup a database for Web access
  • Load a driver
  • Connect to database
  • Create Statement
  • Execute Statement
  • Process the results

Remember to catch errors

Click System DSN tab then Add button
Choose the ODBC Driver and press Finish button

To Configure/Re-Configure a Connection press

File DSN tab, Add, choose Driver and give same

data source as System DSN

Give the path of the database

JDBC Architecture

  • Supports n-Tier architectures
  • Tabular data handling
  • SQL but

not only SQL

JDBC Driver Types

  • JDBC database drivers are classified into four types based on
the nature of the driver provided
1. Bridges. Convert from JDBC to another standard for
example ODBC. That standard then converts into the
vendor specific API.
2. Part Java part Native. Driver contains some Java code
and some Native code
3. Intermediate Server. JDBC talks directly to a separate
server which then converts from JDBC to native API
(great for intranets)
1. Pure Java. JDBC driver converts directly to
native API and sends through vendor specific
network protocol (great for intranets)

CCTM: Course material developed by James King ([email protected]) Docsity.com

The Driver manager

  • It is possible that a Java application may need to talk to multiple
databases, possibly from different vendors (especially if it is a
distributed system)
  • The JDBC driver manager provides the ability to communicate with
multiple databases and keep track of which driver is needed for which
database.
  • Even if you only talk to one database you need to connect to it via the
driver manager

JDBC Driver Manager

ODBC Oracle Driver XYZ Driver

Access (^) Oracle xyzBase

CCTM: Course material developed by James King ([email protected]) Docsity.com

Database

Database

Java JDBC Programming Model

Driver Manager

Connection

Connection

Statement

ResultSet

Statement

ResultSet

SQL

SQL

  • DriverManager allows you to connect to one or more to databases
  • Connection represents the connection to a single database
  • Statement contains an SQL statement to be sent down the connection
to be executed by the database
  • ResultSet contains the results of an SQL query such as SELECT

CCTM: Course material developed by James King ([email protected]) Docsity.com

The JDBC Steps

1. Importing Packages

2. Registering the JDBC Drivers

3. Opening a Connection to a Database

4. Creating a Statement Object

5. Executing a Query and Returning a Result Set

Object

6. Processing the Result Set

7. Closing the Result Set and Statement Objects

8. Closing the Connection

1: Importing Packages

// Program name: LecExample_1a.java
// Purpose: Basic selection using prepared
statement
//Import packages
import java.sql.*; //JDBC packages
import java.math.*;
import java.io.*;
import oracle.jdbc.driver.*;