Importance of databases.
Jdbc key components with steps.
Overview of querying a db with
Advantages and disadvantages.
>Write once, run anywhere
> Multiple client and server platforms
> Java can access any database vendor
> Ease of administration
Importance of databases:
we can store our data permanently by using file concept. If we are using file
concept we have some drawbacks.
•.if we want to use file concept we need to know about IO package concept and
can store small amount of data.
•Inserting , deleting, updating in files it takes more time.
•It does not support query language
•In files we store data in the form of text or objects.
to overcome all these problems we go for database software
In database software the data will be stored permanent it supports query
it takes less time for inserting ,deleting ,updating ,retrieve .
in database s/w the data will be stored in table storing in the form of rows
some of the database software are
odbc is a standard or open application programming
interface (API) for accessing a database.
Handles these requests and converts it into a request
understandable by an individual database system.
Java API for connecting programs written in Java to the
data in relational databases
The standard defined by Sun Microsystems, allowing
individual providers to implement and extend the standard with
their own JDBC drivers.
Tasks of JDBC:
1) establishes a connection with a database
2) sends SQL statements
3) processes the results
JDBC key components:
Driver Manager , Connection , Statement , Result Set
• Driver Manager handles communication with different
drivers that conform to JDBC Driver API
• The static class Driver Manager manages the loaded
drivers and contains methods for accessing connections
to the databases JDBC Driver Manager
Four steps in creating a database
Step 1: load a database driver
Step 2: make a database connection
Step 3: create and execute SQL statement
Step 4: process the result set , if necessary
Step 1: Loading a Driver
•Loading a driver requires class name of the driver
•For JDBC-ODBC driver the class name is: sun. jdbc.Odbc .JdbcOdbcDriver
•The class definition of the driver is loaded using forName static method
of the class Class (in package java.lang )
• catch (Exception e)
Step 2: Opening a Database Connection
• Connection is an interface defined in java.sql package.
A Connection object represents a connection with the
The interface has methods to create statements which
can be used to manipulate the database.
Step 3: Creating Statement & executing SQL
Connection objects can be used to create statement
Statement = cn.createStatement();
Statement is an interface that contains methods for
executing SQL queries
For selection we refer executeQuery()
Step4:Retrieving the data from db
Individual column fields can be retrieved using
the get methods within the ResultSet.
String qry=“select *from employs”;
Resultset is the return type of executeQuery().
Columns may be specified by their field name or
by their index.
Register the driver
Connect to the database
Create a statement
Query the database
Step through the results
Assign results to Java
Close the result set
Close the statement
Close the connection
1) Can read any database if proper drivers are installed.
2) Query and Stored procedure supported.
1) Correct drivers need to be deployed for each type
2) Cannot update or insert multiple tables with
sequence. ( Sequence is always random)
JDBC provides API or Protocol to interact with different databases.
With the help of JDBC driver we can connect with different types of
This technology is an API for the java programming language that defines
how a client may access a database. It provides methods for querying
and updating data in a database. JDBC is oriented towards relational
databases. A JDBC-to-ODBC bridge enables connections to any ODBCaccessible data source in the JVM host environment.