JDBC连接数据库小结

JDBC中有几个与数据库交互的方法:
 
位于java.sql.Statement接口中的方法
  void addBatch(String sql)
          Adds the given SQL command to the current list of commmands for this Statement object.
 booleanexecute(String sql)
          Executes the given SQL statement, which may return multiple results.
 booleanexecute(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.
 booleanexecute(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.
 booleanexecute(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.
 ResultSetexecuteQuery(String sql)
          Executes the given SQL statement, which returns a single ResultSet object.
 intexecuteUpdate(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.
 intexecuteUpdate(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.
 intexecuteUpdate(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.
 intexecuteUpdate(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.
 booleanexecute()
          Executes the SQL statement in this PreparedStatement object, which may be any kind of SQL statement.
 ResultSetexecuteQuery()
          Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.
 intexecuteUpdate()
          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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值