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

国外好的做电视包装的网站大连网络广告

国外好的做电视包装的网站,大连网络广告,wordpress 建商城,一家专做特卖的网站文章目录 前言1、封装数据库连接和关闭操作数据库配置文件 config.properties 2、批量添加操作3、查询操作4、修改和删除操作总结 前言 PreparedStatement是预编译的,对于批量处理可以大大提高效率. 也叫JDBC存储过程 1、封装数据库连接和关闭操作 package org.springblade.m… 文章目录 前言1、封装数据库连接和关闭操作数据库配置文件 config.properties 2、批量添加操作3、查询操作4、修改和删除操作总结 前言 PreparedStatement是预编译的,对于批量处理可以大大提高效率. 也叫JDBC存储过程 1、封装数据库连接和关闭操作 package org.springblade.modules.data.util;import lombok.extern.slf4j.Slf4j;import java.io.IOException; import java.io.InputStream; import java.sql.*; import java.util.*;/*** 数据库连接工具类*/ Slf4j public class JdbcOracleTemplatedct {private static String url;private static String username;private static String password;private static String driver;static {// 加载配置文件InputStream is JdbcOracleTemplatedct.class.getClassLoader().getResourceAsStream(config.properties);Properties pro new Properties();try {pro.load(is);url pro.getProperty(jdbc3.url);username pro.getProperty(jdbc3.username);password pro.getProperty(jdbc3.password);driver pro.getProperty(jdbc3.driverClassName);} catch (IOException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(加载配置文件失败!);}// 注册驱动try {Class.forName(driver);} catch (ClassNotFoundException e) {e.printStackTrace();log.info(e.getMessage(), e);}}public static Connection getConnection() {Connection conn null;try {conn DriverManager.getConnection(url, username, password);// 把jdbc 链接 设置成 非自动提交conn.setAutoCommit(false);} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(获得链接失败!);}return conn;}public static void closeAll(Statement stmt, Connection conn) {if (stmt ! null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn ! null) {try {conn.close();// 关闭} catch (SQLException e) {e.printStackTrace();}}}public static void closeResAll(ResultSet rs, Statement stmt, Connection conn) {if (rs ! null) {try {rs.close();// 关闭} catch (SQLException e) {e.printStackTrace();}}if (stmt ! null) {try {stmt.close();} catch (SQLException e) {e.printStackTrace();}}if (conn ! null) {try {conn.close();// 关闭} catch (SQLException e) {e.printStackTrace();}}}public static boolean createTable(String sqltemplet) {Connection conn getConnection();long starttime System.currentTimeMillis();Statement statement null;boolean isok false;try {try {statement conn.createStatement();} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(执行批处理时 创建预状态通道失败!);}statement.executeUpdate(sqltemplet);isok true;log.info( 执行成功一次,总使用时间 (System.currentTimeMillis() - starttime) ms);} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(在 预 状 态 通 道 下 执 行 批 出 操 作 失 败!);} finally {closeAll(statement, conn);}return isok;}/*** 基于预状态通道执行批处理操作** param sqltemplet* param params* return*/public static boolean batchData(String sqltemplet, ListListObject params) {Connection conn getConnection();long starttime System.currentTimeMillis();PreparedStatement statement null;boolean isok false;try {try {statement conn.prepareStatement(sqltemplet);} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(执行批处理时 创建预状态通道失败!);}if (params ! null !params.isEmpty()) {for (ListObject plist : params) {int size plist.size();for (int i 0; i size; i) {statement.setObject(i 1, plist.get(i));}statement.addBatch();}statement.executeBatch();conn.commit();statement.clearParameters();isok true;log.info( 执行成功一次,总使用时间 (System.currentTimeMillis() - starttime) ms);}} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(在 预 状 态 通 道 下 执 行 批 出 操 作 失 败!);try {conn.rollback();} catch (SQLException e1) {e1.printStackTrace();}} finally {closeAll(statement, conn);}return isok;}/*** 基于预状态通道执行批处理操作** param sqltemplet* param params* return*/public synchronized static boolean batchAllData(String sqltemplet,ListListObject params) {try {Thread.sleep(500);} catch (InterruptedException e2) {e2.printStackTrace();}Connection conn getConnection();long starttime System.currentTimeMillis();PreparedStatement statement null;boolean isok false;try {try {statement conn.prepareStatement(sqltemplet);} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(执行批处理时 创建预状态通道失败!);}if (params ! null !params.isEmpty()) {int size2 params.size();for (int j 0; j size2; j) {ListObject plist params.get(j);int size plist.size();for (int i 0; i size; i) {statement.setObject(i 1, plist.get(i));}statement.addBatch();if (j % 1000 0) {statement.executeBatch();conn.commit();statement.clearParameters();}}statement.executeBatch();conn.commit();statement.clearParameters();isok true;log.info( 执行成功一次,总使用时间 (System.currentTimeMillis() - starttime) ms);}} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);log.info(在 预 状 态 通 道 下 执 行 批 出 操 作 失 败!);try {conn.rollback();} catch (SQLException e1) {e1.printStackTrace();}} finally {closeAll(statement, conn);}return isok;}public static ListMapString, Object selectAll(String querysql) {ListMapString, Object list new ArrayList();long starttime System.currentTimeMillis();Connection conn getConnection();Statement statement null;ResultSet rs null;try {statement conn.createStatement();rs statement.executeQuery(querysql);ResultSetMetaData data rs.getMetaData();int columnCount data.getColumnCount();// System.out.println(columnCount);while (rs.next()) {int i 1;MapString, Object map new HashMapString, Object();while (i columnCount) {String name data.getColumnName(i);// System.out.println(name : rs.getObject(i));if (rs.getObject(i) null || .equals(rs.getObject(i))) {map.put(name, );} else {map.put(name, rs.getObject(i));}i;}list.add(map);}log.info( 执行成功一次,总使用时间 (System.currentTimeMillis() - starttime) ms);} catch (SQLException e) {e.printStackTrace();log.info(e.getMessage(), e);} finally {closeResAll(rs, statement, conn);}return list;}public static void batchUpdate(String sql) {Connection conn null;Statement ps null;try {conn getConnection();ps conn.createStatement();int executeUpdate ps.executeUpdate(sql);conn.commit();} catch (SQLException e) {e.printStackTrace();log.error(e.getMessage(), e);try {conn.rollback();} catch (SQLException e1) {log.error(e1.getMessage(), e1);}} finally {try {ps.close();} catch (SQLException e) {log.error(e.getMessage(), e);}try {conn.close();} catch (SQLException e) {log.error(e.getMessage(), e);}}} }数据库配置文件 config.properties jdbc3.driverClassName oracle.jdbc.OracleDriver jdbc3.url jdbc:oracle:thin:172.0.0.1:1521:rdt1 jdbc3.username root jdbc3.password root2、批量添加操作 public static void main(String[] args) {Connection conn JdbcOracleTemplatedct.getConnection();PreparedStatement statement null;String insertSql INSERT INTO your_table (column1, column2) VALUES (?, ?);try {statement conn.prepareStatement(insertSql);// 假设我们要插入10条数据for (int i 1; i 10; i) {statement.setString(1, Value i Column1);statement.setInt(2, i);statement.addBatch(); // 将SQL语句添加到批处理中}// 执行批处理int[] count statement.executeBatch();System.out.println(插入了 count.length 条数据);} catch (SQLException e) {e.printStackTrace();log.error(添加执行失败, e);} finally {if (statement ! null) {try {statement.close();} catch (SQLException e) {e.printStackTrace();}}}}3、查询操作 如果执行的是查询操作使用executeQuery方法并处理结果集。 ResultSet resultSet statement.executeQuery(); while (resultSet.next()) {// 处理结果集 }4、修改和删除操作 int rowsAffected statement.executeUpdate();总结 通过使用PreparedStatement和executeBatch你可以提高Java应用程序与数据库交互的性能。特别是当你需要执行大量的增删改操作时批处理可以显著减少与数据库的交互次数从而提高效率。同时注意正确处理资源如Connection、PreparedStatement、ResultSet的打开和关闭以及异常处理以确保代码的健壮性。 如果此篇文章有帮助到您, 希望打大佬们能关注、点赞、收藏、评论支持一波非常感谢大家 如果有不对的地方请指正!!!
http://www.hkea.cn/news/14324953/

相关文章:

  • 通辽市城乡建设局网站企业门户网站开发
  • 分类目录网站大全移动端的网站建设
  • 不动产登记门户网站建设如何进行网站建设和推广
  • 站长之家ip地址查询网站备案没有了
  • 网站建设的总结与评价网站建设性能指标
  • 怎么给网站做外链邵连虎网站建设规划方案
  • 林芝北京网站建设wordpress zerif lite
  • 天津建站管理系统信息述职报告ppt免费模板下载
  • 南安市网站建设店面布置效果图大全
  • 空间业务建设网站多个链接的网站怎么做
  • 网站作为医院形象建设北京标本制作
  • c 精品课程建设网站源程序携程网站 建设平台分析
  • 做期货主要看哪几个财经网站徐东做网站
  • 网站建设优化服务行情苏州专业设计网站
  • 华为云 搭建网站专业网站建设86215
  • 惠州网站建设电话网站改版必要性
  • 外贸soho自己建站公司建推广网站多少钱
  • dede网站婚纱模板郴州网站制作公司招聘
  • 网站推广关键词长春网站建设方案托管
  • 珠海网站建设成功案例给宝宝做衣服网站
  • 网站建设步骤图网络建设与运维技能大赛
  • 南宁制作营销型网站做伊瑞尔竞技场的网站
  • 网站建设所需的硬软件苏州360推广 网站建设
  • 郑州七彩网站建设公司 交通网贷代理推广
  • 做付费网站模版网站如何优化
  • 自己网站开发一般网站用什么做的
  • 网站个人和企业有什么区别做影集的网站或软件
  • 地方门户类网站产品推广室内设计者联盟网站
  • 网络营销导向型企业网站建设的原则产品vi设计都包括什么
  • 做服装哪个网站图片多网站需求分析怎么写