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

Loading in 2 Seconds...

play fullscreen
1 / 16

JDBC - PowerPoint PPT Presentation


  • 89 Views
  • Uploaded on

JDBC. Database Connectivity. Relational databases Manage all information generated by businesses Centric to business applications Established and Mature Application developers require standard interface to relational databases

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' - kermit


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
database connectivity
Database Connectivity
  • Relational databases
    • Manage all information generated by businesses
    • Centric to business applications
    • Established and Mature
  • Application developers require standard interface to relational databases
    • Change in database vendor should not require change in application programs
what is jdbc
What is JDBC?
  • A pure Java API for database communication similar to ODBC (JDBC created in 1995)
    • JDBC and ODBC are based on the same standard: X/Open's SQL Call-Level Interface
  • A set of classes that perform database transactions
    • Connect to relational databases
    • Send SQL commands
    • Process results
benefits of jdbc
Benefits of JDBC
  • No proprietary DB code (although pass-through is supported)
  • Don’t have to rely on single vendor...ever
  • Don’t need to make DB vendor decision early
  • Easier for DB vendors
    • Don’t need to provide a query language, only implement API
jdbc api and drivers
JDBC API and Drivers
  • JDBC API is generic: java.sql package
  • A Database system needs to supply a driver.
  • A Java program need to use a specific driver.
jdbc architecture
JDBC Architecture

Java Application

JDBC API

JDBC Driver Manager

JDBC Driver API

(T1) JDBC-

ODBC Bridge

(T4) Java

Driver to

vendor's

protocol

JDBC Drivers

ODBC Driver

Proprietary, vendor-specific

database access protocol

Provided with

Sun's JDK

extracting data from a table
Extracting Data From a Table
  • Need to use SQL:
    • Structured Query Language
    • Language use to communicate with database systems.
    • There are lots of fancy things you can do with SQL, we will just look at simple stuff…
slide8
SQL
  • There are many different types of SQL commands (SELECT is just one).
  • For example: to create a new record:

"INSERT INTO password (Name, Password) VALUES ('Dave', 'blah')"

database interaction
Database Interaction
  • General Idea:
    • establish some kind of connection with a database.
    • send SQL commands.
      • get back error codes, and/or sets of records.
creating a connection
Creating a Connection
  • java.sql.Connection interface corresponds to a session (a connection with a specific database).
  • DriverManager will create a Connection object.

Connection foo = DriverManager.getConnection(DBURL);

two examples
Two Examples
  • MS-SQL Server

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

Connection con = DriverManager.getConnection(“jdbc:microsoft:sqlserver://server1:1433”, userName, password);

  • JDBC-ODBC Bridge

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:people", userName, password);

connection and statement
Connection and Statement
  • Connection:
    • Manage properties of the connection
      • autocommit, etc.
    • create a Statement object
  • Statement:
    • used to execute an SQL statement and retrieve results.

Statement stmt = conn.createStatement ();

resultset
ResultSet
  • A ResultSet is returned when you execute an SQL statement:

ResultSet rs = stmt.executequery("SELECT * FROM password");

using resultset
Using ResultSet
  • Extract rows from the result (step through rows one at a time).
    • Extract a field (column) value from the current row.
      • lots of ways to get at values (as String, int, Object, etc).
example
Example

//name is the 1st attribute of Student

while (rset.next ())

System.out.println (rset.getString (1));

releasing resources
Releasing Resources

//close the result set, statement, and the connection

rset.close();

stmt.close();

conn.close();