0% found this document useful (0 votes)
201 views11 pages

Concept of JDBC

The document discusses the concept of JDBC (Java Database Connectivity), which provides a universal interface for connecting to databases from Java applications. JDBC acts as an interface between Java applications and databases, using drivers to translate requests and responses. There are four types of JDBC drivers: Type I uses ODBC, Type II uses native database APIs, Type III uses network protocols, and Type IV uses native database protocols directly through Java sockets. The basic steps for using JDBC are to load a driver, define a connection URL, establish a connection, create statements, execute queries, process result sets, and close the connection.

Uploaded by

Samir Labh
Copyright
© Attribution Non-Commercial (BY-NC)
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)
201 views11 pages

Concept of JDBC

The document discusses the concept of JDBC (Java Database Connectivity), which provides a universal interface for connecting to databases from Java applications. JDBC acts as an interface between Java applications and databases, using drivers to translate requests and responses. There are four types of JDBC drivers: Type I uses ODBC, Type II uses native database APIs, Type III uses network protocols, and Type IV uses native database protocols directly through Java sockets. The basic steps for using JDBC are to load a driver, define a connection URL, establish a connection, create statements, execute queries, process result sets, and close the connection.

Uploaded by

Samir Labh
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 11

The Concept of JDBC

 ‘Java Database Connectivity’ – JDBC

 JDBC API is the application programming interface that


provides universal data access for the java programming
language Used to build all-Java database applications

 Can interact with multiple database management systems


such as Oracle, MYSQL, SYBASE, MS ACCESS, MS SQL etc..
 
 
Here JDBC layer acts as an interface between the java application and database. The layer
contains drivers such as oracle, SQL, Sybase etc., Driver sends request of java application to
database, after processing the request database sends response to the driver, translates and
sends back the response to jdbc API.
 
Java code calls JDBC library
JDBC loads a driver
Driver talks to a particular database
Can have more than one driver -> more than one database
Ideal: can change database engines without changing any application code
JDBC Drivers Types

There are four important Types of Drivers


 
1. Type I
2. Type II
3. Type III
4. Type IV
Type I Driver - JDBC-ODBC bridge

Type-1 driver allows an application to access the database through ODBC driver. Here ODBC
acts as a mediator between the
jdbc driver and vendors client library.
e.g. ODBC Bridge
Drawbacks:
•ODBC binary code must be loaded on each client.
•Transaction overhead between JDBC and ODBC.
•It doesn’t support all features of Java.
•It works only under Microsoft, SUN operating systems.
Type II Driver - Native-API Partly Java Driver

It converts jdbc calls into calls on clientAPI for dbms. The driver directly communicates with database servers
and therefore some
database client software must be loaded on each client machine and limiting its usefulness for internet.
e.g. Intersolv Oracle Driver, WebLogic drivers
Drawbacks:
•Some database client software must be loaded on each client machine
•Limited functionality
Type III Driver - Net-Protocol All-Java Driver

It is completely implemented in java, hence it is called pure java driver. It translates the jdbc
calls into vendor’s specific protocol which is translated into dbms protocol by a middleware
server.
e.g. Symantec DB
Drawbacks:
It does not support all network protocols.
Every time the net driver is based on other network protocols.
Type IV Driver - Native-Protocol All-Java Driver

Here the driver uses network protocol this protocol is already built-into the database engine;
here the driver talks directly to the database using java sockets. This driver is better than all
other drivers, because this driver supports all network protocols.
  Use Java networking libraries to talk directly to database engines
 Only disadvantage: need to download a new driver for each database engine
 e.g. Oracle, MYSQL
Brief Overview of JDBC Process

Seven Basic Steps in Using JDBC


Drive rMa na ge r
1. Load the Driver
2. Define the Connection URL
Drive r
3. Establish the Connection
4. Create a Statement Object
5. Execute a query Connectio n
6. Process the results
7. Close the Connection State me nt

Res ultSet
1. Load the JDBC driver
When a driver class is first loaded, it registers itself with the driver Manager Therefore, to
register a driver, just load it!
Example:
String driver = “sun.jdbc.odbc.JdbcOdbcDriver”;
Class.forName(driver);
2. Define the Connection URL
jdbc:subprotocol:source
each driver has its own subprotocol
each subprotocol has its own syntax for the source
 
jdbc:odbc:DataSource
e.g. jdbc:odbc:Northwind

jdbc:msql://host[:port]/database
e.g. jdbc:msql://foo.nowhere.com:4333/accounting

3. Establish the Connection


DriverManager Connects to given JDBC URL with given user name and password
Throws java.sql.SQLException
returns a Connection object
A Connection represents a session with a specific database.
Example
Connection con = DriverManager.getConnection (url);
4. Create a Statement Object
A Statement object is used for executing a static SQL statement and obtaining the results
produced by it.
Statement stmt = con.createStatement();

This statement creates a Statement object, stmt that can pass SQL statements to the DBMS
using connection, con.
 5. Execute a query
Execute a SQL query such as SELECT, INSERT, DELETE, UPDATE Example
 
String SelectStudent= "select * from STUDENT";
 
6. Process the results
A ResultSet provides access to a table of data generated by executing a Statement.
Only one ResultSet per Statement can be open at once.
The table rows are retrieved in sequence.
A ResultSet maintains a cursor pointing to its current row of data.
The 'next' method moves the cursor to the next row.
 
7. Close the Connection
connection.close();
– Since opening a connection is expensive, postpone this step if additional database operations
are expected
THANK YOU…

You might also like