Professional Documents
Culture Documents
--------------------------------------------------------------------------------
-----------
DriverManager class
The basic service of driver manager class is to manage JDBC drivers.
DriverManager class will attempt to load the driver classes
This allows a user to customize the JDBC Drivers used by their applications.
there is a special method of Driver manager class i.e getConnection()
when getConnection is called, the DriverManager will attempt to locate a suitabl
e driver from amongst those loaded at initialization and those loaded explicitly
using the same classloader as the current applet or application.
getConnection java ke us driver ka selection karta hai jo mentioned
backend drivers ke saath work kar sakta hai
after this getConnection laid out connection between front end and
back end and reference of same connection will be awarded to
object of Connection interface as in the current case
connection reference goes to "con" object.
in future all transaction with backend in java application will
be carried out using "con" object.
---------------------------------------------------------------------
Statement Interface.
The object of statement interface is used for executing a static SQL statement a
nd returning the results which query may produce.
after executing sql statement it may be that result will come from data base.
e.g
if we issue select * from emp where deptno=20
then n numbers of rows will come from the backend data base.
so where we hold the result which is coming from statement
answer is with in ResultSet object.
ResultSet ob=st.executeQuery("select * from emp");
here st is the object of Statement interface.
executeQuery is the built in method of Statement interface.
Statement interface ka object initialize kaisai karte hai
Connection conn;
conn=DriverManager.getConnection(jdbc:odbc:<dsn name>);
// and after configuring conn object
Statement st=conn.createStatement();
// createStatement() is the built in method of Connection interface.
// createStatement() return Statement object.
// conn object kyu use kiya
// kyo ki sql ki query issue karte waqt wo kis context mai
execute hogi // same info will come from connection objec
t.
after configuring Statement object we are ready to
issue sql queries.
to issue sql command Statement interface provide b
uilt in methods
1. executeUpdate()
Executes the given SQL statement, which may
be an INSERT, UPDATE, or DELETE statement
or an SQL statement that returns nothing,
such as an SQL DDL statement.
Returns:
either the row count for INSERT, UPDATE
or DELETE statements,
or 0 for SQL statements that return nothing
can Throw
SQLException
2. executeQuery()
Executes the given SQL statement, which
returns a single ResultSet object.
Parameters:
sql - an SQL statement to be sent to the database, typically a static SQL SELE
CT statement
Returns:
a ResultSet object that contains the data produced by the given query; never n
ull
Throws:
SQLException - if a database access error occurs or the given SQL s
tatement produces anything other than a single ResultSet object