07JDBC访问数据库.ppt

* * 添加操作 JDBC中也提供了两种实现数据添加操作的方法,一种是通过Statement对象执行静态的SQL语句实现;另一种是通过PreparedStatement对象执行动态的SQL语句实现。 通过Statement对象和PreparedStatement对象实现数据添加操作的方法同实现查询操作的方法基本相同,所不同的就是执行的SQL语句及执行方法不同,实现数据添加操作时采用的是executeUpdate()方法,而实现数据查询时使用的是executeQuery()方法。实现数据添加操作使用的SQL语句为INSERT语句,其语法格式如下: * 添加操作 Statement stmt=conn.createStatement(); int rtn= stmt.executeUpdate(insert into tb_user (name,pwd) values(hope,111)); 应用Statement对象向数据表tb_user中添加数据的关键代码如下: 利用PreparedStatement对象向数据表tb_user中添加数据的关键代码如下: PreparedStatement pStmt = conn.prepareStatement(insert into tb_user (name,pwd) values(?,?)); pStmt.set

文档评论(0)

1亿VIP精品文档

相关文档