美文网首页
chapter12_数据库编程_1_综述

chapter12_数据库编程_1_综述

作者: 米都都 | 来源:发表于2019-01-03 17:06 被阅读0次
  • 标准SQL语言是一种非过程性的数据库操作语言,不能实现控制流程、函数、子程序。

    因此,各个数据库软件都进行了扩展

  • 过程的类型

    (1) 批处理

    将一个或多个SQL语句作为一组,从应用程序发送到数据库服务器。每组将会编译为单个可执行单元

    MySQL添加批处理:在连接数据库URL时,设置参数rewriteBatchedStatements = true(另外还要使用addBatch和executeBatch)

    示例

      public class Solution {
    
          private static String driverName = "com.mysql.jdbc.Driver";
          private static String jdbcURL = "jdbc:mysql://localhost:3306/temp?rewriteBatchedStatements=true";
          private static String databaseUserName = "acba";
          private static String databasePassword = "123456";
    
          private static String sql = "INSERT INTO temp VALUES (?, ?)";
    
          public static void main(String[] args) {
    
              Connection connection = null;
    
              try {
                  Class.forName(driverName);
                  connection = DriverManager.getConnection(jdbcURL, databaseUserName, databasePassword);
    
              } catch (ClassNotFoundException | SQLException e) {
                  e.printStackTrace();
              }
    
              PreparedStatement preparedStatement = null;
      
              try {
                  preparedStatement = connection.prepareStatement(sql);
          
                  // 插入10000条数据
                  for (int i = 0; i < 10000; i++) {
                      preparedStatement.setInt(1, i);
                      preparedStatement.setString(2, String.valueOf(i) + "_bc");
    
                      preparedStatement.addBatch();
                  }
    
                  long startTime = System.currentTimeMillis();
    
                  preparedStatement.executeBatch();
    
                  long endTime = System.currentTimeMillis();
    
                  System.out.println((endTime - startTime)/1000.0);
    
              } catch (SQLException e) {
                  e.printStackTrace();
              } 
          }
      }
    

    实测的结果是,添加了rewriteBatchedStatements = true之后,需要的时间约为0.1秒;不添加大概需要23秒

    (2) 存储过程和触发器

    (3) 脚本

    编写一个.sql文件,然后用mysql自带的Workbench导入执行

相关文章

  • chapter12_数据库编程_1_综述

    标准SQL语言是一种非过程性的数据库操作语言,不能实现控制流程、函数、子程序。因此,各个数据库软件都进行了扩展 过...

  • chapter12_数据库编程_2_游标

    处理多行数据的操作要使用游标cursor 游标有四个基本操作:(1) 声明 DECLARE(2) 打开 OPEN(...

  • 网络编程,TCP,UDP

    day26笔记【网络编程,TCP,UDP】 day26授课目录: 1_网络编程(网络编程概述)(了解) A:计算机...

  • chapter12_数据库编程_3_存储过程

    存储过程(1) 存储过程是一个程序代码,存储在数据库中(2) 作用1° 接受输入参数,并以输出参数的格式向调用过程...

  • chapter12_数据库编程_4_用户定义函数

    函数(1) 函数也是一种存储过程,只不过它可以返回值(2) 返回值可以是单个标量值或结果集(MYSQL中不能返回结...

  • chapter12_数据库编程_5_触发器

    (1) 触发器的作用是实现数据完整性,它比主键、外键、NOT NULL、UNIQUE更加灵活(2) 触发器是特殊的...

  • 肿瘤转移相关lncRNA数据库

    1.写在前面 实验验证的数据库数据库其实和综述差不多。综述是基于一个主题检索相关文献,然后利用文字来进行来进行总结...

  • 2.1_语言/设计模式/框架

    1.主要掌握的编程语言 1_苹果:C,C++,OC,swift 2_安卓/后端: java 3_web:js 4_...

  • 2022年3月6日

    首先,阅读文献的量需要确定,大规模确定,自己思考其中的文献综述,开始尝试国外文献综述 其次,关于编程的学习和基本软...

  • 论文写作降重的心得

    小编对毕业论文查重网站使用 checkvip,因为它的数据库功能齐全,价格实惠。 一、国内外文献综述:外文综述部分...

网友评论

      本文标题:chapter12_数据库编程_1_综述

      本文链接:https://www.haomeiwen.com/subject/qnhqrqtx.html