JDBC Basic Query method

Source: Internet
Author: User

When JDBC operates the database, the most basic three interfaces are statement preparestatment CallableStatement

(1) Statement

createStatement()

createStatement(int resultSetType, int resultSetConcurrency)

createstatement (int resultsettype, int resultsetconcurrency, int resultsetholdability) (JDBC 3.0)

resultSetType-result set type, which is ResultSet.TYPE_FORWARD_ONLY(不可滚动结果集) , ResultSet.TYPE_SCROLL_INSENSITIVE(可滚动结果集,受数据库更新影响的 ) or ResultSet.TYPE_SCROLL_SENSITIVE(可滚动结果集,不 受数据库更新影响的) one of

resultSetConcurrency-concurrency type; it is ResultSet.CONCUR_READ_ONLY (read-only result set) or ResultSet.CONCUR_UPDATABLE (可更新结果集) one.

resultSetHoldability- ResultSet one of the following constants: ResultSet.HOLD_CURSORS_OVER_COMMIT (after committing the modification, do not close the result set) orResultSet.CLOSE_CURSORS_AT_COMMIT (提交修改后,关闭结果集)

Description: The use of resultsettype,resultsetconcurrency,resultsetholdability is limited.

Some databases do not support scrollable result sets, you can update the result set, and you do not close the result set after committing the modification. The DatabaseMetaData object can be obtained by conn.getmetadata () to determine whether the above features are supported.

(2) Preparestatement

prepareStatement(String sql)

prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

prepareStatement(String sql, int autoGeneratedKeys)

prepareStatement(String sql, int[] columnIndexes)

prepareStatement(String sql, String[] columnNames)

Autogeneratedkeys can be used for Statement.return_generated_keys/no_generated_keys

Eg:preparestatement st=conn.preparestatemnt (Sql,statement.return_generated_keys);

ResultSet Rs=st.getgeneratedkeys ();

if (Rs.next ()) {

int Key=ts.getint (1);

}

(3) CallableStatement

Preparecall (String SQL)

prepareCall(String sql, int resultSetType, int resultSetConcurrency)

prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

JDBC Basic Query method

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.