06 Java Database Connectivity
06 Java Database Connectivity
06 Java Database Connectivity
PROGRAMMING
SUBJECT DESCRIPTION: JAVA ENTERPRISE EDITION PROGRAMMING
SUBJECT CODE: CS220
Driver interface
Connection interface
Statement interface
PreparedStatement interface
CallableStatement interface
ResultSet interface
ResultSetMetaData interface
DatabaseMetaData interface
RowSet interface
A list of popular classes of JDBC API are given below:
DriverManager class
Blob class
Clob class
Types class
WHY SHOULD WE USE JDBC?
Before JDBC, ODBC API was the database API to connect and execute the query with the
database. But ODBC API uses ODBC driver that is written in C language (i.e. platform
dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses
JDBC drivers (written in Java language).
We can use JDBC API to handle database using Java program and can perform the following
activities:
JDBC also provides support for handling database metadata that allows us to
retrieve information about the database, such as its tables, columns, and indexes.
We can use the DatabaseMetaData interface to obtain this information that can be
useful for dynamically generating SQL queries or for database schema
introspection.
Another important feature of JDBC is its support for batch processing that allows
us to group multiple SQL statements into a batch and execute them together. It
can improve performance by reducing the number of round trips between the
application and the database.
JDBC DRIVER
JDBC DRIVER
Class.forName("oracle.jdbc.driver.OracleDriver");
2) Create the connection object
The getConnection() method of DriverManager class is used to
establish connection with the database.
Syntax of getConnection() method
1) public static Connection getConnection(String url)throws SQLException
2) public static Connection getConnection(String url,String name,String
password)
throws SQLException
EXAMPLE TO ESTABLISH CONNECTION
WITH THE ORACLE DATABASE
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","password");
3) Create the Statement object
The createStatement() method of Connection interface is used
to create statement. The object of statement is responsible to
execute queries with the database.
Syntax of createStatement() method
public Statement createStatement()throws SQLException
EXAMPLE TO CREATE THE STATEMENT
OBJECT
Statement stmt=con.createStatement();
4) Execute the query
The executeQuery() method of Statement interface is used to
execute queries to the database. This method returns the
object of ResultSet that can be used to get all the records of a
table.
Syntax of executeQuery() method
public ResultSet executeQuery(String sql)throws SQLException
EXAMPLE TO EXECUTE QUERY
con.close();
JAVA DATABASE CONNECTIVITY WITH
ORACLE
JAVA DATABASE CONNECTIVITY WITH
ORACLE
To connect java application with the oracle database, we need to follow 5 following
steps. In this example, we are using Oracle 10g as the database. So we need to
know following information for the oracle database:
Driver class: The driver class for the oracle database is oracle.jdbc.driver.OracleDriver.
Connection URL: The connection URL for the oracle10G database
is jdbc:oracle:thin:@localhost:1521:xe where jdbc is the API, oracle is the database, thin
is the driver, localhost is the server name on which oracle is running, we may also use IP
address, 1521 is the port number and XE is the Oracle service name. You may get all these
information from the tnsnames.ora file.
Username: The default username for the oracle database is system.
Password: It is the password given by the user at the time of installing the oracle database.
CREATE A TABLE
}
}
To connect java application with the Oracle database
ojdbc14.jar file is required to be loaded.
TWO WAYS TO LOAD THE JAR FILE:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from login");
while(rs.next()){
System.out.println(rs.getString(1));
}
}catch(Exception ee){System.out.println(ee);}
EXAMPLE TO CONNECT JAVA APPLICATION
WITH ACCESS WITH DSN
while(rs.next()){
System.out.println(rs.getString(1));
}
}catch(Exception ee){System.out.println(ee);}
}}
DRIVERMANAGER CLASS
The DriverManager class is the component of JDBC API and also a member of
the java.sql package. The DriverManager class acts as an interface between users and
drivers. It keeps track of the drivers that are available and handles establishing a
connection between a database and the appropriate driver. It contains all the
appropriate methods to register and deregister the database driver class and to create
a connection between a Java application and the database. The DriverManager class
maintains a list of Driver classes that have registered themselves by calling the method
DriverManager.registerDriver(). Note that before interacting with a Database, it is a
mandatory process to register the driver; otherwise, an exception is thrown.
METHODS OF THE DRIVERMANAGER
CLASS
CONNECTION INTERFACE
A Connection is a session between a Java application and a database. It
helps to establish a connection with the database.
The Connection interface is a factory of Statement, PreparedStatement,
and DatabaseMetaData, i.e., an object of Connection can be used to get
the object of Statement and DatabaseMetaData. The Connection
interface provide many methods for transaction management like
commit(), rollback(), setAutoCommit(), setTransactionIsolation(), etc.
By default, connection commits the changes after executing queries.
COMMONLY USED METHODS OF
CONNECTION INTERFACE:
• 1) public Statement createStatement(): creates a statement object that can be used to
execute SQL queries.
• 2) public Statement createStatement(int resultSetType,int
resultSetConcurrency): Creates a Statement object that will generate ResultSet objects with
the given type and concurrency.
• 3) public void setAutoCommit(boolean status): is used to set the commit status. By default,
it is true.
• 4) public void commit(): saves the changes made since the previous commit/rollback is
permanent.
• 5) public void rollback(): Drops all changes made since the previous commit/rollback.
• 6) public void close(): closes the connection and Releases a JDBC resources immediately.
CONNECTION INTERFACE FIELDS
There are some common Connection interface constant fields that are present in the Connect interface.
These fields specify the isolation level of a transaction.
• TRANSACTION_NONE: No transaction is supported, and it is indicated by this constant.
• TRANSACTION_READ_COMMITTED: It is a constant which shows that the dirty reads are not
allowed. However, phantom reads and non-repeatable reads can occur.
• TRANSACTION_READ_UNCOMMITTED: It is a constant which shows that dirty reads, non-repeatable
reads, and phantom reads can occur.
• TRANSACTION_REPEATABLE_READ: It is a constant which shows that the non-repeatable reads and
dirty reads are not allowed. However, phantom reads and can occur.
• TRANSACTION_SERIALIZABLE: It is a constant which shows that the non-repeatable reads, dirty
reads as well as the phantom reads are not allowed.
STATEMENT INTERFACE
The Statement interface provides methods to execute
queries with the database. The statement interface is a factory
of ResultSet i.e. it provides factory method to get the object of
ResultSet.
COMMONLY USED METHODS OF
STATEMENT INTERFACE:
The important methods of Statement interface are as follows:
ResultSet.CONCUR_UPDATABLE);
COMMONLY USED METHODS OF
RESULTSET INTERFACE
EXAMPLE OF SCROLLABLE RESULTSET
Let’s see the simple example of ResultSet interface to retrieve the data of
3rd row. import java.sql.*;
class FetchRecord{
public static void main(String args[])throws Exception{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:x
e","system","oracle");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSe
t.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from emp765");
con.close();
}}
PREPAREDSTATEMENT INTERFACE
PREPAREDSTATEMENT INTERFACE
As you can see, we are passing parameter (?) for the values. Its value
will be set by calling the setter methods of PreparedStatement.
WHY USE PREPAREDSTATEMENT?
class InsertPrepared{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
stmt.setString(2,"Ratan");
int i=stmt.executeUpdate();
con.close();
}
EXAMPLE OF PREPAREDSTATEMENT
INTERFACE THAT UPDATES THE RECORD
PreparedStatement stmt=con.prepareStatement("update emp set name=? whe
re id=?");
stmt.setString(1,"Sonoo");//
1 specifies the first parameter in the query i.e. name
stmt.setInt(2,101);
int i=stmt.executeUpdate();
stmt.setInt(1,101);
int i=stmt.executeUpdate();
ResultSet rs=stmt.executeQuery();
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
EXAMPLE OF PREPAREDSTATEMENT TO
INSERT RECORDS UNTIL USER PRESS N
import java.sql.*; float salary=Float.parseFloat(br.readLine());
import java.io.*;
class RS{ ps.setInt(1,id);
public static void main(String args[])throws Exception{ ps.setString(2,name);
Class.forName("oracle.jdbc.driver.OracleDriver"); ps.setFloat(3,salary);
Connection con=DriverManager.getConnection("jdbc:oracle:thin: int i=ps.executeUpdate();
@localhost:1521:xe","system","oracle");
System.out.println(i+" records affected");
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
Output:
Total columns: 2
Column Name of 1st column: ID
Column Type Name of 1st column: NUMBER
JAVA DATABASEMETADATA INTERFACE
DatabaseMetaData interface provides methods to get meta
data of a database such as database product name, database
product version, driver name, name of total number of tables,
name of total number of views etc.
COMMONLY USED METHODS OF
DATABASEMETADATA INTERFACE
• public String getDriverName()throws SQLException: it returns the name of the JDBC driver.
• public String getDriverVersion()throws SQLException: it returns the version number of the JDBC
driver.
• public String getUserName()throws SQLException: it returns the username of the database.
• public String getDatabaseProductName()throws SQLException: it returns the product name of
the database.
• public String getDatabaseProductVersion()throws SQLException: it returns the product version
of the database.
• public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern,
String[] types)throws SQLException: it returns the description of the tables of the specified
catalog. The table type can be TABLE, VIEW, ALIAS, SYSTEM TABLE, SYNONYM etc.
HOW TO GET THE OBJECT OF
DATABASEMETADATA:
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
DatabaseMetaData dbmd=con.getMetaData();
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
Output:Driver Name: Oracle JDBC
Driver Driver Version: 10.2.0.1.0XE
Database Product Name: Oracle
Database Product Version: Oracle Database 10g
Express Edition Release 10.2.0.1.0 -Production
EXAMPLE OF DATABASEMETADATA
INTERFACE THAT PRINTS TOTAL NUMBER
OF TABLES :
import java.sql.*;
class Dbmd2{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
DatabaseMetaData dbmd=con.getMetaData();
String table[]={"TABLE"};
ResultSet rs=dbmd.getTables(null,null,null,table);
while(rs.next()){
System.out.println(rs.getString(3));
}
con.close();
}
}
EXAMPLE OF DATABASEMETADATA
INTERFACE THAT PRINTS TOTAL NUMBER
OF VIEWS :
import java.sql.*;
class Dbmd3{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
DatabaseMetaData dbmd=con.getMetaData();
String table[]={"VIEW"};
ResultSet rs=dbmd.getTables(null,null,null,table);
while(rs.next()){
System.out.println(rs.getString(3));
}
con.close();
}
}
EXAMPLE TO STORE IMAGE IN ORACLE
DATABASE
You can store images in the database in java by the help
of PreparedStatement interface.
The setBinaryStream() method of PreparedStatement is
used to set Binary information into the parameterIndex.
SIGNATURE OF SETBINARYSTREAM
METHOD
throws SQLException
throws SQLException
For storing image into the database, BLOB (Binary Large Object) datatype is used in the table. For example:
CREATE TABLE "IMGTABLE"
( "NAME" VARCHAR2(4000),
"PHOTO" BLOB
Let's write the jdbc code to store the image in the database. Here we are using d:\\d.jpg for the location of
image. You can change it according to the image location.
JAVA EXAMPLE TO STORE IMAGE IN THE
DATABASE
import java.sql.*;
import java.io.*;
public class InsertImage {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
con.close();
}catch (Exception e) {e.printStackTrace();}
}
}
EXAMPLE TO RETRIEVE IMAGE FROM
ORACLE DATABASE
By the help of PreparedStatement we can retrieve and store the
image in the database.
The getBlob() method of PreparedStatement is used to get Binary
information, it returns the instance of Blob. After calling
the getBytes() method on the blob object, we can get the array of
binary information that can be written into the image file.
SIGNATURE OF GETBLOB() METHOD OF
PREPAREDSTATEMENT
( "NAME" VARCHAR2(4000),
"PHOTO" BLOB
/
Now let's write the code to retrieve the image from the database and write it into
the directory so that it can be displayed.
In AWT, it can be displayed by the Toolkit class. In servlet, jsp, or html it can be
displayed by the img tag.
import java.sql.*;
import java.io.*;
public class RetrieveImage {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
fout.close();
}//end of if
System.out.println("ok");
con.close();
}catch (Exception e) {e.printStackTrace(); }
}
}
EXAMPLE TO STORE FILE IN ORACLE
DATABASE:
The setCharacterStream() method of PreparedStatement is
used to set character information into the parameterIndex.
Syntax:
1) public void setBinaryStream(int paramIndex,InputStream
stream)throws SQLException
2) public void setBinaryStream(int paramIndex,InputStream
stream,long length)throws SQLException
For storing file into the database, CLOB (Character Large Object) datatype is used in the
table. For example:
CREATE TABLE "FILETABLE"
( "ID" NUMBER,
"NAME" CLOB
/
JAVA EXAMPLE TO STORE FILE IN
DATABASE
import java.io.*;
import java.sql.*;
PreparedStatement ps=con.prepareStatement(
"insert into filetable values(?,?)");
ps.setInt(1,101);
ps.setCharacterStream(2,fr,(int)f.length());
int i=ps.executeUpdate();
System.out.println(i+" records affected");
con.close();
( "ID" NUMBER,
"NAME" CLOB
/
The example to retrieve the file from the Oracle database is given below.
import java.io.*;
import java.sql.*;
Clob c=rs.getClob(2);
Reader r=c.getCharacterStream();
int i;
while((i=r.read())!=-1)
fw.write((char)i);
fw.close();
con.close();
System.out.println("success");
}catch (Exception e) {e.printStackTrace(); }
}
}
JAVA CALLABLESTATEMENT INTERFACE
CallableStatement interface is used to call the stored procedures and
functions.
We can have business logic on the database by the use of stored procedures and
functions that will make the performance better because these are precompiled.
Suppose you need the get the age of the employee based on the date of birth,
you may create a function that receives date as the input and returns age of the
employee as the output.
WHAT IS THE DIFFERENCE BETWEEN
STORED PROCEDURES AND FUNCTIONS.
The differences between stored procedures and functions are given below:
HOW TO GET THE INSTANCE OF
CALLABLESTATEMENT?
The prepareCall() method of Connection interface returns the instance of
CallableStatement. Syntax is given below:
public CallableStatement prepareCall("{ call procedurename(?,?...?)}");
(id IN NUMBER,
name IN VARCHAR2)
is
begin
end;
/
The table structure is given below:
create table user420(id number(10), name varchar2(200));
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
System.out.println("success");
}
}
EXAMPLE TO CALL THE FUNCTION USING
JDBC
In this example, we are calling the sum4 function that receives two input and
returns the sum of the given number. Here, we have used
the registerOutParameter method of CallableStatement interface, that
registers the output parameter with its corresponding type. It provides
information to the CallableStatement about the type of result being displayed.
The Types class defines many constants such as INTEGER, VARCHAR, FLOAT,
DOUBLE, BLOB, CLOB etc.
Let's create the simple function in the database
first.
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
System.out.println(stmt.getInt(1));
}
}
TRANSACTION MANAGEMENT IN JDBC
Transaction represents a single unit of work.
The ACID properties describes the transaction management well. ACID stands for Atomicity,
Consistency, isolation and durability.
Atomicity means either all successful or none.
Consistency ensures bringing the database from one consistent state to another consistent state.
Isolation ensures that transaction is isolated from other transaction.
Durability means once a transaction has been committed, it will remain so, even in the event of
errors, power loss etc.
ADVANTAGE OF TRANSACTION
MANAGEMENT
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:orac
le:thin:@localhost:1521:xe","system","oracle");
con.setAutoCommit(false);
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into user420 values(190,'abhi
',40000)");
stmt.executeUpdate("insert into user420 values(191,'ume
If you see the
table emp400, sh',50000)");
you will see that
2 records has con.commit();
been added.
con.close();
}}
EXAMPLE OF TRANSACTION
MANAGEMENT IN JDBC USING
PREPAREDSTATEMENT
import java.sql.*; ps.setInt(3,salary);
import java.io.*; ps.executeUpdate();
class TM{
public static void main(String args[]){ System.out.println("commit/rollback");
try{ String answer=br.readLine();
if(answer.equals("commit")){
Class.forName("oracle.jdbc.driver.OracleDriver"); con.commit();
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localho }
st:1521:xe","system","oracle"); if(answer.equals("rollback")){
con.setAutoCommit(false); con.rollback();
}
PreparedStatement ps=con.prepareStatement("insert into user420 values
(?,?,?)");
System.out.println("Want to add more records y/n");
BufferedReader br=new BufferedReader(new InputStreamReader(System String ans=br.readLine();
.in)); if(ans.equals("n")){
while(true){ break;
}
System.out.println("enter id");
String s1=br.readLine(); }
int id=Integer.parseInt(s1); con.commit();
System.out.println("record successfully saved");
System.out.println("enter name");
String name=br.readLine(); con.close();//before closing connection commit() is called
}catch(Exception e){System.out.println(e);}
System.out.println("enter salary");
String s3=br.readLine(); }}
int salary=Integer.parseInt(s3);
ps.setInt(1,id);
BATCH PROCESSING IN JDBC
Instead of executing a single query, we can execute a batch (group) of
queries. It makes the performance fast. It is because when one sends
multiple statements of SQL at once to the database, the communication
overhead is reduced significantly, as one is not communicating with the
database frequently, which in turn results to fast performance.
The java.sql.Statement and java.sql.PreparedStatement interfaces provide
methods for batch processing.
ADVANTAGE OF BATCH PROCESSING
Fast Performance
METHODS OF STATEMENT INTERFACE
EXAMPLE OF BATCH PROCESSING IN JDBC
Let's see the simple example of batch processing in JDBC. It follows following
steps:
Load the driver class
Create Connection
Create Statement
Add query in the batch
Execute Batch
Close Connection
EXAMPLE OF BATCH PROCESSING USING
PREPAREDSTATEMENT
import java.sql.*; String s3=br.readLine();
import java.io.*; int salary=Integer.parseInt(s3);
class BP{
public static void main(String args[]){ ps.setInt(1,id);
try{ ps.setString(2,name);
ps.setInt(3,salary);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle: ps.addBatch();
thin:@localhost:1521:xe","system","oracle"); System.out.println("Want to add more records y/n");
String ans=br.readLine();
PreparedStatement ps=con.prepareStatement("insert into u if(ans.equals("n")){
ser420 values(?,?,?)"); break;
}
BufferedReader br=new BufferedReader(new InputStreamR }
eader(System.in)); ps.executeBatch();// for executing the batch
while(true){
System.out.println("record successfully saved");
System.out.println("enter id");
String s1=br.readLine(); con.close();
int id=Integer.parseInt(s1); }catch(Exception e){System.out.println(e);}
System.out.println("enter name"); }}
String name=br.readLine();
System.out.println("enter salary");
OUTPUT:
enter id 103
101 enter name
enter name Rohit Anuragi
Manoj Kumar enter salary
enter salary 30000
10000 Want to add more records y/n
Want to add more records y/n y
y enter id
enter id 104
101 enter name
enter name Amrit Gautam
Harish Singh enter salary
enter salary 40000
15000 Want to add more records y/n
Want to add more records y/n n
y record successfully saved
enter id
JDBC ROWSET
An instance of RowSet is the Java bean component because it has properties and Java bean
notification mechanism. It is the wrapper of ResultSet. A JDBC RowSet facilitates a mechanism to keep
the data in tabular form. It happens to make the data more flexible as well as easier as compared to a
ResultSet. The connection between the data source and the RowSet object is maintained throughout
its life cycle. The RowSet supports development models that are component-based such as JavaBeans,
with the standard set of properties and the mechanism of event notification.
It was in the JDBC 2.0, the support for the RowSet was introduced using the optional packages. But the
implementations were standardized for RowSet in the JDBC RowSet Implementations Specification (JSR-
114) by the Sun Microsystems that is being present in the JDK (Java Development Kit) 5.0.
The implementation classes of the
RowSet interface are as follows:
JdbcRowSet
CachedRowSet
WebRowSet
JoinRowSet
FilteredRowSet
ADVANTAGE OF ROWSET
while (rowSet.next()) {
// Generating cursor Moved event
System.out.println("Id: " + rowSet.getString(1));
System.out.println("Name: " + rowSet.getString(2));
System.out.println("Salary: " + rowSet.getString(3));
}
}
}
THE OUTPUT IS GIVEN BELOW:
Id: 55
Name: Om Bhim
Salary: 70000
Id: 190
Name: abhi
Salary: 40000
Id: 191
Name: umesh
Salary: 50000
EXAMPLE OF JDBC ROWSET WITH EVENT
HANDLING
To perform event handling with JdbcRowSet, you need to add the instance
of RowSetListener in the addRowSetListener method of JdbcRowSet.
The RowSetListener interface provides 3 method that must be
implemented. They are as follows:
public void cursorMoved(RowSetEvent event);
public void rowChanged(RowSetEvent event);
public void rowSetChanged(RowSetEvent event);
import java.sql.Connection; // Generating cursor Moved event
import java.sql.DriverManager; System.out.println("Id: " + rowSet.getString(1));
import java.sql.ResultSet; System.out.println("Name: " + rowSet.getString(2));
import java.sql.Statement; System.out.println("Salary: " + rowSet.getString(3));
import javax.sql.RowSetEvent; }
import javax.sql.RowSetListener;
import javax.sql.rowset.JdbcRowSet; }
import javax.sql.rowset.RowSetProvider; }
while (rowSet.next()) {
THE OUTPUT IS AS FOLLOWS:
Cursor Moved...
Id: 55
Name: Om Bhim
Salary: 70000
Cursor Moved...
Id: 190
Name: abhi
Salary: 40000
Cursor Moved...
Id: 191
Name: umesh
Salary: 50000
Cursor Moved...
MULTIPLE CHOICE QUESTIONS ON JDBC IN
JAVA
JDBC is an API (Application Programming Interface) that helps a programmer
to write a Java program to connect to a database, retrieve the data from the
database, and perform various operations on the data in a Java program.
As it is an important topic, the questions related to JDBC frequently asked in
Java interviews and competitive exams. So, in this section, we have collected
some multiple-choice questions based on JDBC that are important from
the perspective of different competitive exams and interviews.
WHAT ARE THE MAJOR COMPONENTS OF
THE JDBC?
DriverManager: Manages a list of database drivers.
Driver: The database communications link, handling all communication
with the database.
Connection: Interface with all methods for contacting a database.
Statement: Encapsulates an SQL statement which is passed to the
database to be parsed, compiled, planned, and executed.
ResultSet: The ResultSet represents a set of rows retrieved due to
query execution.
PACKAGES IN WHICH JDBC CLASSES ARE
DEFINED?
JDBC Net pure Java driver (Type 4) is the fastest driver because
it converts the JDBC calls into vendor-specific protocol calls and
it directly interacts with the database.
THREE TYPES OF RESULTSET OBJECT
• TYPE_FORWARD_ONLY: This is the default type and the cursor can only move
forward in the result set.
• TYPE_SCROLL_INSENSITIVE: The cursor can move forward and backward, and
the result set is not sensitive to changes made by others to the database after the
result set was created.
• TYPE_SCROLL_SENSITIVE: The cursor can move forward and backward, and the
result set is sensitive to changes made by others to the database after the result
set was created.
BASED ON THE CONCURRENCY THERE
ARE TWO TYPES OF RESULTSET OBJECT.