java database connectivity · 2/5/2018 · resultset objects. close_cursors_at_commit resultset...
TRANSCRIPT
![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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/1.jpg)
ADVANCED FEATURES
Java Database Connectivity
Dr. Syed Imtiyaz HassanAssistant Professor, Deptt. of CSE,
Jamia Hamdard (Deemed to be University), New
Delhi, India.
![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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/9.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/10.jpg)
• 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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/14.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/16.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/18.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/19.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/21.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/22.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/23.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022050402/5f7fece67a2517735b0cd708/html5/thumbnails/24.jpg)
Thank You
SRC: https://www.dreamstime.com/stock-photo-network-connectivity-c-image22362970