slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
JDBC PowerPoint Presentation
Download Presentation
JDBC

Loading in 2 Seconds...

play fullscreen
1 / 19

JDBC - PowerPoint PPT Presentation


  • 122 Views
  • Uploaded on

JDBC. Java API for Database Connectivity. Layout of this recitation. Introduction to JDBC API JDBC Architecture Understanding the design of JDBC API Classes and relations among them. What is an API?. a pplication p rogram i nterface

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'JDBC' - roary-brennan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

JDBC

Java API for Database Connectivity

layout of this recitation
Layout of this recitation
  • Introduction to JDBC API
  • JDBC Architecture
  • Understanding the design of JDBC API
    • Classes and relations among them
what is an api
What is an API?
  • application program interface
  • a set of routines, protocols, and tools for building software applications
  • provides all the building blocks
what you expect in db api
What you expect in DB API

Java Application

Java DB API

  • Open a Connection
  • Send a statement
  • Retrieve results
  • Close a connection

DBMS Engine

  • Create a connection Session
  • Execute statement
  • Send results
  • Close the session
big picture
Big picture

Java Application

JDBC API

JDBC Manager

JDBC Driver API

JDBC Drivers

Grey Area

Data Sources

jdbc driver type 1
JDBC driver type-1
  • Uses the existing API
  • Not the fastest

JDBC-ODBC Bridge

Java

ODBC Driver

Native Driver

Non Java

Net Driver

jdbc driver type 2
JDBC driver type-2
  • Uses vendor-provided local libraries
  • Most efficient

JDBC Driver

Java

Native Driver

Non Java

Net Driver

jdbc driver type 3 4
JDBC driver type-3 & 4
  • 100% java.

JDBC – Net Driver

Java

JDBC Driver

Implements a proprietary

Protocol in java

Java

complete jdbc architecture
Complete JDBC Architecture

Java Application

JDBC Interface

JDBC Driver Manager

JDBC Driver Interface

JDBC Net Driver A

JDBC–ODBC Bridge B

JDBC Driver C

JDBC Driver D

ODBC Driver

Native Driver C

Native Driver B

A

B

C

D

on different platforms
On Different Platforms

JDBC Driver Classes

JDBC API

PC

DBMS

MAC

Unix

jdbc interface classes
JDBC Interface classes
  • Java.sql package
    • DriverManager
    • Connection
    • Statement
    • CallableStatement
    • PreparedStatement
    • Resultset
    • ResultSetMetaData
    • DatabaseMetatData
jdbc interfaces
JDBC Interfaces

Driver Manager

Connection

Connection

Connection

Statement

Prepared

Statement

ResultSet

simple example
Simple Example

Import java.sql;

class SimpleExample {

public static void main(String args[]) {

String url = “jdbc:odbc:mysource”;

try {

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

Connection myConnection =

DriverManager.getConnection(url,”Bond”,”TopSecret”);

myConnection.close();

}

catch(java.lang.Exception) {

ex.printStackTrace();

}

}

}

sending sql statements
Sending SQL statements

……

String query= “Select name,id,salary FROM employees ORDER By salary”;

Connection myConnection = DriverManager.getConnection(…..);

Statement myStatement = myConnection.createStatement();

ResultSet rs = myStatement.executeQuery(query);

While(rs.next){

String empName = rs.getString(1);

String empId = rs.getString(2);

String empSalary = rs.getString(3);

System.out.println(“Employee ” + empName + “ with id ” + empId

+ “ earns ” + empSalary);

}

myStatement.close();

myConnection.close();

…….

statement s execute methods
Statement’s Execute Methods
  • ResultSet executeQuery()
    • For SQL selects
  • int executeUpdate()
    • For Update,Delete,Insert and Create etc.
  • boolean execute()
    • For either type
    • Returns resultSetisAvailable
statements
Statements
  • Statement
  • PreparedStatement
  • CallableStatement
additional stuff
Additional stuff
  • Datatypes: basic to CLOB, BLOB
  • Transaction Management
  • DDA with/without cursors
  • Batch updates
  • Metadata
    • DatabaseMetaData
    • ResultSetMetaData
    • ParameterMetaData
advanced techniques
Advanced Techniques
  • Connection Pooling
  • Dynamic SQL with Prepared Statements
  • Auto-generated keys
references
References
  • www.google.com
  • http://java.sun.com/j2se/1.4/docs/api/
  • JDBC 3.0: Java Database Connectivity.
    • Bernard Van Haecke