网站大量收购独家精品文档,联系QQ:2885784924

数据库实验知识要点讲述.doc

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
数据库实验知识要点讲述

执行JDBC 执行SQL的整体流程: 加载驱动:Class.forName(“……”)//注意try...catch 获取连接:DriverManager.getConnection(url,psw,psw); 创建Statement/PreparedStatement:con.createStatement();或者con.prepareStatement(sql,...,...); 执行SQL语句: (PreparedStatement )pret.setString(index,value);pret.executeQuery();pret.executeUpdate(); (Statement)stmt.executeUpdate(sql)/stmt.executeQuery(sql); 如果是Query,返回结果集Result,对结果集进行处理,如果是Update,返回SQL语句影响数据条数。 关闭连接释放资源。 对Connection的处理: 主要有三个: 设置自动提交:con.setAutoCommit(false); 提交:mit(); 回滚:con.rollback(); 关闭:con.close(); 对Statement的处理: 主要有三种处理:查询、修改(增删改)、批处理: 查询: stmt.executeQuery(sql);//sql为SQL语句 修改: stmt.executeUpdate(sql);//sql为SQL语句 批处理: stmt.addBatch(sql);//sql为单条SQL语句 stmt.executeBatch(); 注意:Statement使用完后需要关闭:stmt.close(); 对PreparedStatement的处理 PreparedStatement运行的速度比Statement快,使用方式也比Statement繁琐。网上有评论说稍微有点经验的程序员都应该不使用Statement而使用PreparedStatement。 首先从PreparedStatement的创建讲起: PreparedStatement的创建主要有两种方式: prepareStatement(String?sql) sql通常是由占位符‘?’的sql语句 prepareStatement(String?sql, int?resultSetType, int?resultSetConcurrency) resultSetType是结果集类型, static int TYPE_FORWARD_ONLY The constant indicating the type for a ResultSet object whose cursor may move only forward. static int TYPE_SCROLL_INSENSITIVE The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet. static int TYPE_SCROLL_SENSITIVE The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet. TYPE_FORWORD_ONLY,只可向前滚动; 2.TYPE_SCROLL_INSENSITIVE,双向滚动,但不及时更新,就是如果数据库里的数据修改过,并不在ResultSet中反应出来。 3.TYPE_SCROLL_SENSITIVE,双向滚动,并及时跟踪数据库的更新,以便更改ResultSet中的数据。 resultSetConcurrency:结果集并发性。 static int CONCUR_READ_ONLY The constant indicating the concurrency mode for a ResultSet object that may NOT be updated. static int CONCUR_UPDATABL

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档