Sei sulla pagina 1di 3

Introduction to JDBC:

JDBC is the mechanism supported by the sun-microsystem to communicate with any


database such as oracle, mysql database through the java application.
The sun-microsystem provide some pre-defined interfaces that is readymade interfaces
with a package called java.sql. So that any user of JDBC application can import and use
these interfaces to communicate with any database through his JDBC application.
The following are the list of interfaces available in java.sql package.
1) Connection
2) Statement
3) ResultSet
4) PreparedStatement
5) CallableStatement
6) ResultSetMetaData
7) DatabaseMetaData
All the interfaces are defined by the sun-microsystems with set of abstractspecification
functions related to the database without any implemented details.
The vendor of the database such as oracle database provides the implementation classes
of these interfaces which are called as JDBC driver classes.
Architecture of JDBC application:
We should load the all JDBC driver classes provided by the vendor of the database into
classes segment of JDBC application, so that the objects of these classes can be created
according to the application requirements.
Syntax:

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

We should establish the connection to the database from the JDBC application, so that we
can communicate with database from the java application through this established
connection.
Syntax:

DriverManager.getConnection (jdbc: odbc: ora,scott,tiger);

We should create one Statement interface object in the JDBC application, so that we can
send the required sql commands to the database from the JDBC application through the
vendor implemented methods available in Statement interface object.
Syntax:
Statement stmt = con.createStament();
The following are the two vendor implemented methods of Statement interface object can
used to send the required sql commands as string values to the database from the JDBC
application.
1.

executeUpdate(String s);

2.

executeQuery(String s);

executeUpdate:
The executeUpdate method of Statement interface object can be used to send the sql
commands such as Create, Insert, Update, Delete as the string value to the database from
the JDBC application.
The return type of this method is integer.
executeQuery:
The executeQuery method of Statement interface object can be used to send the Select sql
command to the database as a string value to get the data from any database table into
JDBC application.
The return type of this method is ResultSet.
Resultset :
The ResultSet represents set of rows retrieved due to query execution.
PreparedStatement :
A prepared statement is an SQL statement that is precompiled by the database. Through
precompilation, prepared statements improve the performance of SQL commands that are
executed multiple times (given that the database supports prepared statements). Once
compiled, prepared statements can be customized prior to each execution by altering
predefined SQL parameters.
CallableStatement :
Callable statements are used from JDBC application to invoke stored procedures and
functions.

ResultSetMetaData :
Data about data is called metadata.
This ResultSetMetaData interface is used in the JDBC application to get the details about
the ResultSet object. Such as no.of columns available in ResultSet, Column names,
Column types e.t.c.

DatabasetMetaData:
This DatabaseMetaData interface is used in the JDBC application to get the details about
the database, where the connection is established such as database name , database
version, JDBC driver classes version, list of all keywords supported by the database e.t.c.

Potrebbero piacerti anche