java database connectivity · 2/5/2018  · resultset objects. close_cursors_at_commit resultset...

Post on 30-Jul-2020

8 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ADVANCED FEATURES

Java Database Connectivity

Dr. Syed Imtiyaz HassanAssistant Professor, Deptt. of CSE,

Jamia Hamdard (Deemed to be University), New

Delhi, India.

s.imtiyaz@jamiahamdard.ac.in

Agenda

Scrollable Resultset

Updatable Resultset

Cursor & Holdability

Optinal Package

Connection Pooling

JNDI

Datasource

Rowset

Summary

References

Provides methods for retrieving and manipulating the results of

executed queries

Scrollable

Can move both forward and backward relative to the current

position

Can move to an absolute position

Updatable

Can be updated

Reflects changes made to the underlying data source while

the result set remains open

Characteristics

Type

Concurrency

cursor holdability

Resultset Interface

Determines the level of functionality in two areas

The ways in which the cursor can be manipulated

How concurrent changes made to the underlying data source

are reflected by the ResultSet object

Resultset Interface … (cont.)

Resultset Type Description

ResultSet.TYPE_FORWARD_ONLYThe result set cannot be scrolled; its cursor moves forward only,

from before the first row to after the last row.

ResultSet.TYPE_SCROLL_INSENSITIVE

The result can be scrolled; its cursor can move both forward and

backward relative to the current position, and it can move to an

absolute position. The result set is insensitive to changes made to

the underlying data source while it is open.

ResultSet.TYPE_SCROLL_SENSITIVE

The result can be scrolled; its cursor can move both forward and

backward relative to the current position, and it can move to an

absolute position. The result set reflects changes made to the

underlying data source while the result set remains open.

Resultset Interface … Type

next()

previous()

first()

last()

beforeFirst()

afterLast()

relative(int rows)

absolute(int row)

Resultset Interface … Cursors

Program

ScrollableResultSetClass

Concurrency Description

ResultSet.CONCUR_READ_ONLYThe ResultSet object cannot be updated using the

ResultSet interface.

ResultSet.CONCUR_UPDATABLEThe ResultSet object can be updated using the

ResultSet interface.

Determines what level of update functionality is supported

Resultset Interface … Concurrency

Scrollable

ResultSet

next()

previous()

relative()

absolute()

first()

last()

Cursor Table

Oracle 8i

Statement stmt = con.createStatemen(

ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCURR_READ_ONLY);

ResultSet rset = stmt.executeQuery();

rset.absolute(2);

...

Java Program

Cache

Resultset Interface … Scrollable

Statement createStatement(int resultSetType, int resultSetConcurrency)

PreparedStatement prepareStatement(String sql, int resultSetType, int

resultSetConcurrency)

Resultset Interface … Scrollable & Updatable

• void deleteRow(int row) throws SQLException

• void updateXXX(int idx, XXX x) throws SQLException

• void updateRow() throws SQLException

• void moveToInsertRow () throws SQLException

• void moveToCurrentRow() throws SQLException

• void insertRow() throws SQLException

Resultset Interface … APIs

Program

UpdatableResultSetClass

Calling the method Connection.commit can close the

ResultSet objects

In some cases, however, this may not be the desired

behavior.

The ResultSet property holdability gives the application

control over whether ResultSet objects (cursors) are closed

when commit is called.

Resultset Interface … Cursor Holdability

Holdability Description

HOLD_CURSORS_OVER_COMMIT

ResultSet cursors are not closed; they are

holdable: they are held open when the method

commit is called. Holdable cursors might be

ideal if your application uses mostly read-only

ResultSet objects.

CLOSE_CURSORS_AT_COMMIT

ResultSet objects (cursors) are closed when the

commit method is called. Closing cursors when

this method is called can result in better

performance for some applications.

prepStmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);

Resultset Interface … Cursor Holdability (cont.)

JDBC API

Core package (java.sql package)

Optional Package (javax.sql package)

Core package

Optional package

Connection Pool

DataSource

JNDI

RowSets

Connection Pool

Data Source

JNDI

Overall Picture

RowSet

RowSet … (cont.)

Summary

JDBC Basicshttps://docs.oracle.com/javase/tutorial/jdbc/basics/index.html

References

Thank You

SRC: https://www.dreamstime.com/stock-photo-network-connectivity-c-image22362970

top related