0% found this document useful (0 votes)
2 views

Database_(1)[1]

mm

Uploaded by

kenabadane9299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Database_(1)[1]

mm

Uploaded by

kenabadane9299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Java Database Connectivity

Java Database Connectivity (JDBC)

Database and SQL


 SQL commands are divided into four categories

1. DDL (Data Definition Language)


 Define data (create table)

2. DML (Data Manipulation Language)


 Insert ,Delete and update

3. DCL (Data Control Language)


 Grant

4. Query (select)
Java Database Connectivity (JDBC Programming)

 JDBC is an API used to connect Java application with database


 Is used to interact with various type of database i.e. Ms Access, MYSQL and SQL
Server
Java Application
 JDBC Architecture

JDBC API

JDBC DriverManager

JDBC Driver JDBC Driver


Java Database Connectivity (JDBC
Programming)
What is ODBC
 Before JDBC, ODBC API was used to communicate with the databases
 ODBC API uses ODBC drivers to interact with the databases.
 Written in c language
 Platform dependent
 Unsecured
 ODBC requires manual installation of ODBC driver
Java Database Connectivity (Types of JDBC
JDBC Driver Drivers)
 Is a software component that enables java application to interact with the database .
 There are four types of JDBC drivers

1. JDBC-ODBC bridge driver


‾ Uses ODBC driver to connect to the database
‾ It converts JDBC method calls into the ODBC function calls
‾ Easy to use
‾ Can be easily connected to any database
‾ Performance degraded
‾ The ODBC driver needs to be installed
Java Database Connectivity (Types of JDBC
2. Native – API driver Drivers)
‾ Uses client side libraries of the database
‾ Converts JDBC method calls into native calls of the database
‾ It is written in java
‾ Performance upgraded than JDBC-ODBC bridge driver
‾ The native driver needs to be installed

3. Network protocol driver


‾ Uses middleware (Application server) that converts JDBC calls into database protocol
‾ Written in java
‾ No client side library is required
‾ Network support is required
‾ Maintenance of network protocol driver becomes costly
Java Database Connectivity (Types of JDBC
Drivers)
4. Thin driver
‾ Thin driver converts JDBC calls into database protocol
‾ Written in java
‾ Better performance that all other drivers
‾ No software is required
‾ Drivers depends on the database
Java Database Connectivity (Overview of JDBC
API)
JDBC API
 Is a java application programming interface to develop DBMS independent java
applications using a uniform interface.
 Consists of classes and interfaces

The driver Interface


 The driver interface is database specific

 The driver must be loaded before connecting to a database, to locate, load and link the
driver class.
Java Database Connectivity (Overview of JDBC
API)
The DriverManager class
 A layer of JDBC working b/n the driver and the user

 It keep track the registered drivers connection between the database and the driver

The Connection Interface


 A connection instance represents a session with a specific database

 SQL statements are sent to the database for execution and returns the results of the
execution
Java Database Connectivity (Overview of JDBC
API)
The Statement Interface
 Is used to execute a static SQL statement

 executeQuery

 ExecuteUpdate

The ResultSet Interface


 Provides access to a table of data generated by executing a statement

 It maintains a cursor pointing to its current row of data

 Cursor movement methods (absolute, first, last, next and previous)


Java Database Connectivity (Overview of JDBC
API)
The SQL Exception classes
 Provides information on a database access error.

The DatabaseMetaData Interface


 Enables to obtain information about the database

 E.g. tables, columns, PK, FK


Six basic steps in using JDBC

 Load the driver

 Establish the connection

 Create the statement object

 Execute query

 Process the result

 Close the connection


Java Database Connectivity ( Steps to connect a java application to
database )

1. Register the driver


 Class.forName() is used to load the driver

 E.g. Class. forName(“Com.mysql.jdbc.Driver”);

2. Create a connection
 getConnection() method of DriverManger class is used to create a connection

 getConnection(String url, String user, String Pass);

 E.g. getConection(“Jdbc:mysql, localhost:3306/Student, “user”, “pass””);

3. Create SQL statement


 createStatment() method is invoked on current connection object to create a SQL statement.

 Statement s= con.createStatement();
Java Database Connectivity ( Steps to connect a java application to
database )

4. Execute SQL statement


 executeQuery() method of statement interface is used to execute SQL statement

 E.g. ResultSet rs= s.executeQuery(“select * from user”);

5. Closing the connection


 The close() method connection interface is used to close the connection.

You might also like