Jdbc 存储过程 procedure

2024-02-26 14:32
文章标签 jdbc 过程 存储 procedure

本文主要是介绍Jdbc 存储过程 procedure,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

           今天闲暇之余 ,就测试使用存储过程来操作数据库和使用 JDBC方式来操作数据库的效率比较。

           废话不说了,看如下sql , 创建了表和存储过程供调用。

create table `operators_man` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `old_pid` varchar(100) DEFAULT NULL COMMENT '要摘除的pid',
  `from_lid` varchar(100) DEFAULT NULL COMMENT '来源数据的 lid',
  `new_pid` varchar(100) DEFAULT NULL COMMENT '要摘入的pid ',
  `operator` varchar(100) DEFAULT NULL COMMENT '操作者',
  `operator_time` datetime DEFAULT NULL COMMENT '操作时间',
  `tempStr0` varchar(100) DEFAULT NULL COMMENT '备用',
  `tempStr1` varchar(100) DEFAULT NULL COMMENT '备用',
  `tempStr2` varchar(100) DEFAULT NULL COMMENT '备用',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='人物摘除操作记录表';

#
# procedure insert_operators_man
#
drop procedure if exists insert_operators_man;
create procedure insert_operators_man(
    in oldpid varchar(20),
    in fromlid varchar(20),
    in newpid varchar(20),
    in operatorman varchar(20),
    in operatortime varchar(50)
)
begin
    insert into operators_man(old_pid,from_lid,new_pid,operator,operator_time) VALUES ( oldpid,fromlid,newpid,operatorman,operatortime );
end;

#
# procedure update_operators_man
#
drop procedure if exists update_operators_man;
create procedure update_operators_man(
    in opid int(11),
    in oldpid varchar(20),
    in fromlid  varchar(20),
    in newpid varchar(20),
    in operatorman varchar(20),
    in operatortime varchar(50)
)
begin
    update  operators_man set old_pid=oldpid,from_lid=fromlid,new_pid=newpid,operator=operatorman,operator_time=operatortime where id = opid;
end;

#
# procedure delete_operators_man
#
drop procedure if exists delete_operators_man;
create procedure delete_operators_man(
    in opid int(10)
)
begin
    delete from  operators_man  where id = opid;
end;

#
# procedure find_operators_man
#
drop procedure if exists find_operators_man;
create procedure find_operators_man(
    in opid int(10)
)
begin
    select *  from  operators_man  where id = opid;
end;

     

    创建完成之后,就去调用,看代码:

       /**
     * insert
     * @return
     * @throws SQLException
     */
    public static List<OperatorMan> find_OperatorMan(Connection conn){
        try {
            CallableStatement cell=(CallableStatement) conn.prepareCall("{call find_operators_man(?)}");  
            cell.setInt(1, 2);
            //执行
            List<OperatorMan> list = new ArrayList<OperatorMan>();
            boolean result = cell.execute();
            if(result) {
                ResultSet resultSet = cell.getResultSet();
                while (resultSet!=null && resultSet.next()) {
                    OperatorMan man = new OperatorMan();
                    man.setId(resultSet.getInt("id"));
                    man.setOld_pid(resultSet.getString("old_pid"));
                    man.setFrom_lid(resultSet.getString("from_lid"));
                    man.setNew_pid(resultSet.getString("new_pid"));
                    man.setOperator(resultSet.getString("operator"));
                    man.setOperator_time(resultSet.getDate("operator_time"));
                    man.setTempStr0(resultSet.getString("tempStr0"));
                    man.setTempStr1(resultSet.getString("tempStr1"));
                    man.setTempStr2(resultSet.getString("tempStr2"));
                    //add...
                    list.add(man);
                }
            }
            return list;
        } catch (Exception e) {
            System.out.println(e.getLocalizedMessage());
            return null;
        }
    }


           当使用这些个做1000w 的CRUD之后,对比JDBC,速度的确快出很多来,主要原因在于:  存储过程是一组编译好的sql , 程序可以自然去调用,少去编译的过程,这就无形中加快了速度。

          以上是针对单个操作,效率比JDBC方式来的快,但是要是JDBC使用批处理操作,经过测试,使用的效率是逊色于JDBC的,看来没有什么是一定不变的,凡事都要根据

情况而定,这样才能够很好的去解决问题。

          性能和效率确实是一个比较头疼的问题,很难做到把这个做到性能最优,效率最高。。。


这篇关于Jdbc 存储过程 procedure的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/749167

相关文章

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

PLsql Oracle 下载安装图文过程详解

《PLsqlOracle下载安装图文过程详解》PL/SQLDeveloper是一款用于开发Oracle数据库的集成开发环境,可以通过官网下载安装配置,并通过配置tnsnames.ora文件及环境变... 目录一、PL/SQL Developer 简介二、PL/SQL Developer 安装及配置详解1.下

在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程

《在Java中使用ModelMapper简化Shapefile属性转JavaBean实战过程》本文介绍了在Java中使用ModelMapper库简化Shapefile属性转JavaBean的过程,对比... 目录前言一、原始的处理办法1、使用Set方法来转换2、使用构造方法转换二、基于ModelMapper

springboot启动流程过程

《springboot启动流程过程》SpringBoot简化了Spring框架的使用,通过创建`SpringApplication`对象,判断应用类型并设置初始化器和监听器,在`run`方法中,读取配... 目录springboot启动流程springboot程序启动入口1.创建SpringApplicat

本地搭建DeepSeek-R1、WebUI的完整过程及访问

《本地搭建DeepSeek-R1、WebUI的完整过程及访问》:本文主要介绍本地搭建DeepSeek-R1、WebUI的完整过程及访问的相关资料,DeepSeek-R1是一个开源的人工智能平台,主... 目录背景       搭建准备基础概念搭建过程访问对话测试总结背景       最近几年,人工智能技术

Redis存储的列表分页和检索的实现方法

《Redis存储的列表分页和检索的实现方法》在Redis中,列表(List)是一种有序的数据结构,通常用于存储一系列元素,由于列表是有序的,可以通过索引来访问元素,因此可以很方便地实现分页和检索功能,... 目录一、Redis 列表的基本操作二、分页实现三、检索实现3.1 方法 1:客户端过滤3.2 方法

Linux部署jar包过程

《Linux部署jar包过程》文章介绍了在Linux系统上部署Java(jar)包时需要注意的几个关键点,包括统一JDK版本、添加打包插件、修改数据库密码以及正确执行jar包的方法... 目录linux部署jar包1.统一jdk版本2.打包插件依赖3.修改密码4.执行jar包总结Linux部署jar包部署

C++中使用vector存储并遍历数据的基本步骤

《C++中使用vector存储并遍历数据的基本步骤》C++标准模板库(STL)提供了多种容器类型,包括顺序容器、关联容器、无序关联容器和容器适配器,每种容器都有其特定的用途和特性,:本文主要介绍C... 目录(1)容器及简要描述‌php顺序容器‌‌关联容器‌‌无序关联容器‌(基于哈希表):‌容器适配器‌:(

使用MongoDB进行数据存储的操作流程

《使用MongoDB进行数据存储的操作流程》在现代应用开发中,数据存储是一个至关重要的部分,随着数据量的增大和复杂性的增加,传统的关系型数据库有时难以应对高并发和大数据量的处理需求,MongoDB作为... 目录什么是MongoDB?MongoDB的优势使用MongoDB进行数据存储1. 安装MongoDB