Provides the API for accessing and processing data stored in a data source (usually a relational database) using the Java programming language. This API includes a framework whereby different drivers can be installed dynamically to access different data sources. Although the JDBC API is mainly geared to passing SQL statements to a database, it provides for reading and writing data from any data source with a tabular format. The reader/writer facility, available through the javax.sql.RowSet group of interfaces, can be customized to use and update data from a spread sheet, flat file, or any other tabular data source.
graph TD
A[导入JDBC] --> B{加载JDBC数据库驱动};
B --> C[DriverManager获取Connection];
C --> D{创建Statement或PreparedStatement};
D --> E[执行SQL语句];
E --> F{处理ResultSet};
F --> G[关闭ResultSet/Statement/Connection];
G --> J[结束];
subgraph "1. 准备驱动"
A
B
C
end
subgraph "2. 执行SQL"
D
E
end
subgraph "3. 处理与关闭"
F
J
end
C -- 失败 --> K((SQLException));
E -- 失败 --> K;
F -- 失败 --> K;
void setAutoCommit(boolean autoCommit) throws SQLException Sets this connection's auto-commit mode to the given state. If a connection is in auto-commit ?>mode, then all its SQL statements will be executed and committed as individual transactions. >Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either >the method commit or the method rollback. By default, new connections are in auto-commit >mode. The commit occurs when the statement completes. The time when the statement completes >depends on the type of SQL Statement:
For DML statements, such as Insert, Update or Delete, and DDL statements, the statement is >complete as soon as it has finished executing.
For Select statements, the statement is complete when the associated result set is closed.
For CallableStatement objects or for statements that return multiple results, the statement is >complete when all of the associated result sets have been closed, and all update counts and >output parameters have been retrieved.
NOTE: If this method is called during a transaction and the auto-commit mode is changed, the >transaction is committed. If setAutoCommit is called and the auto-commit mode is not changed, >the call is a no-op.
Parameters: autoCommit - true to enable auto-commit mode; false to disable it Throws: SQLException - if a database access error occurs, setAutoCommit(true) is called while >participating in a distributed transaction, or this method is called on a closed connection See Also: getAutoCommit()