In-depth analysis of resultset

Source: Internet
Author: User

If ($ ('hunter _ recommended ')){
$ ('Hunter _ recommended'). setstyle ({cssfloat: 'left', width: '557px '})
}
New draggable ("related_topics ");

First, let's take a look at the method for creating a statement, createstatement ();

Jdbc1.0: createstatement ()

Jdbc2.0: createstatement (resultsettype, resultsetconcurrency)

Jdbc3.0: createstatement (resultsettype, resultsetconcurrency, resultsetholdability)

There are three parameters mentioned in these methods. Each parameter can make the resultset have some advanced functions and attributes.

Resultsettype 

The optional resultsettype values include: resultset. type_forward_only, resultset. type_scroll_insensitive, and resultset. type_scroll_sensitive.

1 : Resultset. type_forward_only

The default cursor type only supports the result set forward. operations such as backforward, random, last, and first are not supported.

2 : Resultset. type_scroll_insensitive

Supports operations such as result set backforward, random, last, and first. Changes made to data in the database by other sessions are not sensitive.

Implementation Method: After the data is retrieved from the database, all the data is cached to the cache. Subsequent operations on the result set are performed on the data in the cache. After the record changes in the database, the data in the cache is not affected, so the data in the result set of resultset isInsensitive.

3 : Resultset. type_scroll_sensitive

Supports operations such as result set backforward, random, last, and first. Changes made to data in the database by other sessions are sensitive, that is, other sessions modify data in the database, will be reflected in this result set.

Implementation Method: After the data is retrieved from the database, instead of caching all the data into the cache, The rowid of each data is cached into the cache. For subsequent operations on the result set, it is used to retrieve data from the database based on rowid. Therefore, after the record changes in the database, the records retrieved through the resultset are the latest, that is, the resultset isSensitive. However, the insert and delete operations do not affect the resultset. Because the rowid of the insert data is not included in the rowid retrieved by the resultset, the insert data is invisible to the resultset, the rowid of the delete data is still in the resultset, so the resultset can still retrieve the deleted records (because the deletion of a database is marked as deleted, rather than deleted in a database file ).

II resultsetconcurrency

Resultsetconcurrency has two optional values:
Resultset. concur_read_only data records in resultset are read-only and cannot be modified.
The data records of resultset. concur_updatable in resultset can be modified at will, updated to the database, and inserted, deleted, and modified.

Resultsetholdability

Resultsetholdability has two optional values:

Hold_cursors_over_commit: after the transaction commit or rollback, The resultset is still available.
Close_cursors_at_commit: after the transaction commit or rollback, The resultset is disabled.

Note:

1: Oracle only supports hold_cursors_over_commit.

2: When statement executes the next query and generates the second resultset, the first resultset will be disabled, regardless of whether hold_cursors_over_commit is supported.

4. verify whether the database supports the features of resultset.

Different database versions and JDBC driver versions support different advanced features of resultset. We can verify the specific database and JDBC driver by using the following methods, whether to support various features of resultset.

Databasemetadata dbmeta = conn. getmetadata ();

Then, call the following method of the databasemetadata object:

Boolean supportsresultsettype (INT resultsettype );

Boolean supportsresultsetconcurrency (INT type, int concurrency );

Boolean supportsresultsetholdability (INT holdability );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.