JDBC中有几个与数据库交互的方法:
位于java.sql.Statement接口中的方法
Adds the given SQL command to the current list of commmands for this
位于java.sql.PreparedStatement接口中的方法:
Adds a set of parameters to this
调用数据的存储过程(procedure):
java.sql
主键相关
Creates a default
位于java.sql.Statement接口中的方法
void
addBatch(String sql)
Adds the given SQL command to the current list of commmands for this
Statement
object.
boolean | execute(String sql) Executes the given SQL statement, which may return multiple results. |
boolean | execute(String sql, int autoGeneratedKeys) Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval. |
boolean | execute(String sql, int[] columnIndexes) Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
boolean | execute(String sql, String[] columnNames) Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
int[] | executeBatch() Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. |
ResultSet | executeQuery(String sql) Executes the given SQL statement, which returns a single ResultSet object. |
int | executeUpdate(String sql) Executes the given SQL statement, which may be an INSERT , UPDATE , or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. |
int | executeUpdate(String sql, int autoGeneratedKeys) Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval. |
int | executeUpdate(String sql, int[] columnIndexes) Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
int | executeUpdate(String sql, String[] columnNames) Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval. |
位于java.sql.PreparedStatement接口中的方法:
void
addBatch()
Adds a set of parameters to this
PreparedStatement
object's batch of commands.
boolean | execute() Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement. |
ResultSet | executeQuery() Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query. |
int | executeUpdate() Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT , UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement. |
调用数据的存储过程(procedure):
java.sql
Interface CallableStatement
主键相关
PreparedStatement
prepareStatement(String sql, int autoGeneratedKeys)
Creates a default
PreparedStatement
object that has the capability to retrieve auto-generated keys