Home  >  Article  >  Java  >  Detailed explanation of java's createStatement() method

Detailed explanation of java's createStatement() method

怪我咯
怪我咯Original
2017-06-30 10:30:063533browse

This article mainly introduces the relevant information about the detailed explanation of the createStatement() method in java. Friends who need it can refer to

The detailed explanation of the instance of the createStatement() method in java

When created with default settings, ResultSet is a object that can only be accessed once (one-time-through), forward-only (forward-only), and read-only. You can only access the data once. If you need the data again, you must query the database again.

However, this is not the only way. By setting parameters on a Statement object, you can control the ResultSet it produces. For example:

...
     Class.forName(driverName);
     db = DriverManager.getConnection(connectURL);
     Statement statement = db.createStatement(
              ResultSet.TYPE_SCROLL_SENSITIVE,
                         ResultSet.CONCUR_UPDATABLE
            );     
     
     String orderElName = xmlfileEl.getElementsByTagName("order").item(0)
                    .getFirstChild().getNodeValue();
...

This Statement will now produce a ResultSet that can be updated and will apply changes made by other database users. You can also move forward and backward within this ResultSet.

The first parameter specifies the type of ResultSet. The options are:

TYPE_FORWARD_ONLY: Default type. Forward access is allowed only once and is not affected by changes made to the database by other users.

TYPE_SCROLL_INSENSITIVE: Allows moving forward or backward in the list, and even specific positioning, such as moving to the fourth record in the list or backward from the current position Move two records. It is not affected by changes made to the database by other users.

TYPE_SCROLL_SENSITIVE: Like TYPE_SCROLL_INSENSITIVE, allows positioning within the record. This type is affected by changes made by other users. If the user deletes a record after executing the query, that record will disappear from the ResultSet. Similarly, changes to data values ​​will also be reflected in the ResultSet.

The second parameter sets the concurrency of the ResultSet, which determines whether the ResultSet can be updated. The options are:

CONCUR_READ_ONLY: This is the default value, specifying that the ResultSet cannot be updated

CONCUR_UPDATABLE: Specifying that the ResultSet can be updated

The above is the detailed content of Detailed explanation of java's createStatement() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn