Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet...

24
ADVANCED FEATURES Java Database Connectivity Dr. Syed Imtiyaz Hassan Assistant Professor, Deptt. of CSE, Jamia Hamdard (Deemed to be University), New Delhi, India. [email protected]

Transcript of Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet...

Page 1: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

ADVANCED FEATURES

Java Database Connectivity

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

Jamia Hamdard (Deemed to be University), New

Delhi, India.

[email protected]

Page 2: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Agenda

Scrollable Resultset

Updatable Resultset

Cursor & Holdability

Optinal Package

Connection Pooling

JNDI

Datasource

Rowset

Summary

References

Page 3: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

Page 4: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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.)

Page 5: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

Page 6: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

next()

previous()

first()

last()

beforeFirst()

afterLast()

relative(int rows)

absolute(int row)

Resultset Interface … Cursors

Program

ScrollableResultSetClass

Page 7: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

Page 8: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

Page 9: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Statement createStatement(int resultSetType, int resultSetConcurrency)

PreparedStatement prepareStatement(String sql, int resultSetType, int

resultSetConcurrency)

Resultset Interface … Scrollable & Updatable

Page 10: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

• 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

Page 11: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

Page 12: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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.)

Page 13: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

JDBC API

Core package (java.sql package)

Optional Package (javax.sql package)

Page 14: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Core package

Page 15: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Optional package

Connection Pool

DataSource

JNDI

RowSets

Page 16: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Connection Pool

Page 17: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Data Source

Page 18: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

JNDI

Page 19: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Overall Picture

Page 20: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

RowSet

Page 21: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

RowSet … (cont.)

Page 22: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Summary

Page 23: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

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

References

Page 24: Java Database Connectivity · 2/5/2018  · ResultSet objects. CLOSE_CURSORS_AT_COMMIT ResultSet objects (cursors) are closed when the commit method is called. Closing cursors when

Thank You

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