当前位置: 首页 > news >正文

淘宝做任务网站基于php+mysql的网站开发

淘宝做任务网站,基于php+mysql的网站开发,做搜狗pc网站优化排,哈尔滨建设工程信息网站描述当我们需要在Java程序中与数据库进行交互#xff0c;可能首先想到的是使用某个ORM框架#xff0c;因为ORM框架封装了一些实现细节#xff0c;在使用上非常方便#xff0c;并且一定程度上可以提升代码稳定性。在ORM框架中#xff0c;都会依赖MySQL Connector包#xf…描述当我们需要在Java程序中与数据库进行交互可能首先想到的是使用某个ORM框架因为ORM框架封装了一些实现细节在使用上非常方便并且一定程度上可以提升代码稳定性。在ORM框架中都会依赖MySQL Connector包因为真正与数据库进行交互的是在MySQL Connector包里面实现。5.x版本maven依赖mysqlmysql-connector-java5.1.47三种方式MySQL Connector执行SQL语句主要有executeQueryexecuteUpdateexecute等三种方式。executeQuery此方法执行Selec查询语句通过ResultSet返回结果集。private static void executeQuery() throws Exception{Connection connection null;Statement statement null;ResultSet rs null;try {connection DriverManager.getConnection(url);statement connection.createStatement();statement.setFetchSize(Integer.MIN_VALUE);String sql select * from user;rs statement.executeQuery(sql);int count0;while (rs.next()){count;}System.out.println(executeQuery count: count);} catch (Exception e){e.printStackTrace();} finally {close(connection,statement,rs);}}executeUpdate此方法执行InsertUpdateDelete语句返回变更影响的行数。private static void executeUpdate() throws Exception{Connection connection null;Statement statement null;int updateCount 0;try {connection DriverManager.getConnection(url);statement connection.createStatement();String sql update user set name啊啊啊 where id new Random().nextInt(999999);updateCount statement.executeUpdate(sql);System.out.println(executeUpdate count: updateCount);} catch (Exception e){e.printStackTrace();} finally {close(connection,statement,null);}}execute当我们不知道来源SQL是Select查询还是Insert/Update/Delete更新时可以统一使用excute()方法来执行SQL语句此方法返回一个boolean值如果返回true表示执行的SQL语句为Select查询语句此时可以通过Statement#getResultSet()方法来获取结果集如果返回false表示执行的时Insert/Update/Delete语句此时可以通过Statement#getUpdateCount()来返回此次SQL执行对数据库影响的行数。private static void executeForSelect() throws Exception{Connection connection null;Statement statement null;ResultSet rs null;try {connection DriverManager.getConnection(url);statement connection.createStatement();statement.setFetchSize(Integer.MIN_VALUE);String sql select * from user;if (statement.execute(sql)){rs statement.getResultSet();}int count0;while (rs.next()){count;}System.out.println(executeForSelect count: count);} catch (Exception e){e.printStackTrace();} finally {close(connection,statement,rs);}}private static void executeForUpdate() throws Exception{Connection connection null;Statement statement null;int updateCount 0;try {connection DriverManager.getConnection(url);statement connection.createStatement();String sql update user set name啊啊啊 where id new Random().nextInt(999999);if (!statement.execute(sql)){updateCount statement.getUpdateCount();}System.out.println(executeForUpdate updateCount: updateCount);} catch (Exception e){e.printStackTrace();} finally {close(connection,statement,null);}}验证执行测试public static void main(String[] args) throws Exception {Long start System.currentTimeMillis();executeForSelect();System.out.println(executeForSelect 耗时 (System.currentTimeMillis() - start) ms \n);start System.currentTimeMillis();executeForUpdate();System.out.println(executeForUpdate 耗时 (System.currentTimeMillis() - start) ms \n);start System.currentTimeMillis();executeQuery();System.out.println(executeQuery 耗时 (System.currentTimeMillis() - start) ms \n);start System.currentTimeMillis();executeUpdate();System.out.println(executeUpdate 耗时 (System.currentTimeMillis() - start) ms \n);}private static void close(Connection connection, Statement statement, ResultSet rs) throws Exception{if (rs ! null){rs.close();}if (statement ! null){statement.close();}if (connection ! null){connection.close();}}返回结果executeForSelect count: 4717924executeForSelect 耗时 4791 msexecuteForUpdate updateCount: 1executeForUpdate 耗时 6 msexecuteQuery count: 4717924executeQuery 耗时 4340 msexecuteUpdate count: 1executeUpdate 耗时 8 ms
http://www.sadfv.cn/news/446893/

相关文章:

  • 龙岗汤坑社区网站建设wordpress 慢途网主题
  • 电子商务网站建设与维护书如何做一款app
  • 自动成交型网站建设松江品划做网站
  • 南昌企业建站系统网站开发哈尔滨网站开发公司
  • 同城类网站建设多少钱注册德国网站域名
  • 萝岗门户网站建设html教材电子版
  • 网站设计职业培训上海工商网查询营业执照
  • 陶艺品网站模板justnews主题wordpress
  • 域名怎么建网站网站开发会什么软件
  • 做拍卖网站网站建设公司使用图片侵权使用者有无责任
  • 个人网站的设计及实现湖州住房建设部网站
  • 个人做跨境电商的平台网站有哪些网站建设预算方案
  • 2021建站舆情分析研判报告
  • 为朋友做的网站微信怎么开通公众号
  • 企业网站哪家好汽车营销策划方案ppt
  • 网站建设进度表模板下载网站 自适应文字大小怎么做
  • 巴中免费网站建设阜宁做网站价格
  • 天津网站制作福州建设银行网站用户名
  • 一般做自己的网站需要什么网页游戏排行榜前十名国战
  • 招标网站排行榜找家里做的工作到什么网站
  • 淮北建设工程质量安全站网站一元购物网站建设
  • 手机网站建设怎样ppt模板免费下载的网站
  • 短视频素材下载网站建设工程项目的组成
  • 中国水利建设网站网站建设全包哪家便宜
  • 自己网站内容怎么才能被百度抓取国际军事新闻最新消息视频
  • 广州网站建设出售网站建设开票内容是什么意思
  • 纯静态网站怎么做凡科建站网站建设
  • 嘉兴网站建设网站建设wordpress错误页
  • 购买域名后 可以做网站么seo外链平台
  • 呼市网站建设公司简述网站开发基本流程图