jdbc fetchsize_Sharding-JDBC

jdbc fetchsize_Sharding-JDBCDBUtilscommons-dbutils是Apache组织提供的一个开源JDBC工具类库,封装了针对于数据库的增删改查操作APIQueryRunnerResulSetHandlerDbutils插入举例Connection conn = null; try { QueryRunner runner = new QueryRunner(); conn = JBBCUtils.getConnections3();

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

DBUtils


commons-dbutils是Apache组织提供的一个开源JDBC工具类库,封装了针对于数据库的增删改查操作

API

  • QueryRunner
  • ResulSetHandler
  • Dbutils

插入举例

Connection conn = null;
        try { 
   
            QueryRunner runner = new QueryRunner();
            conn = JBBCUtils.getConnections3();
            String sql = "insert into customers(name,emial,birth) values(?,?,?)";
            int insertCount = runner.update(conn,sql,"蔡旭坤","caixukun@163.com","1993-03-01");
            System.out.println(insertCount);
        } catch (SQLException throwables) { 
   
            throwables.printStackTrace();
        }finally { 
   
            JDBCUtils.closeResource(conn,null);
        }

更新


    public static void main(String[] args) { 
   

        Connection conn = null;
        try { 
   
            QueryRunner runner = new QueryRunner();
            conn = JBBCUtils.getConnections3();
            String sql = "select id,name,email,birth from customers where id < ?";
            BeanListHandler<Customer> handler = new BeanListHandler<Cunstomer>(customer.class);
            List<Customer> query = runner.query(conn.sql, handler, 23);
            System.out.println(insertCount);
        } catch (SQLException throwables) { 
   
            throwables.printStackTrace();
        }finally { 
   
            JDBCUtils.closeResource(conn,null);
        }
    }

查询表中特殊值

public static void main(String[] args) { 
   

        Connection conn = null;
        try { 
   
            QueryRunner runner = new QueryRunner();
            conn = JBBCUtils.getConnections3();
            String sql = "select count(*) from customers";
            ScalarHandler handler = new ScalarHandler();
            
            Long count = (Long)runner.query(conn.sql, handler);
            System.out.println(count);
        } catch (SQLException throwables) { 
   
            throwables.printStackTrace();
        }finally { 
   
            JDBCUtils.closeResource(conn,null);
        }
    }

自定义ResultSetHandler

public static void main(String[] args) { 
   

        Connection conn = null;
        try { 
   
            QueryRunner runner = new QueryRunner();
            conn = JBBCUtils.getConnections3();
            String sql = "select id,name,email,birth from customers where id = ?";
            ResultSetHandler<Customers> resultSetHandler = new ResultSetHandler<Customers>() { 
   
                @Override
                public Customers handle(ResultSet rs) throws SQLException { 
   
                    if(resultSet.next()){ 
   
                        int id = rs.getInt(1);
                        String name = rs.getString(2);
                        String email = rs.getString(3);
                        Date birth = rs.getDate(4);
                        Customer customer = new Cunstomer(id,name,email,birth);
                        return customer;
                    }
                    return null;
                }
            };

            Long count = (Long)runner.query(conn.sql, handler);
            System.out.println(count);
        } catch (SQLException throwables) { 
   
            throwables.printStackTrace();
        }finally { 
   
            JDBCUtils.closeResource(conn,null);
        }
    }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/168819.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • django drf_mnbkdrf

    django drf_mnbkdrf前言我们上篇文章使用到了Serializer类,可能有小伙伴说太过复杂,那么本篇就为大家带来更加简便的序列化类ModelSerializerModelSerializer先来看下ModelSer

    2022年8月7日
    6
  • vsftp怎么用_c++ ftp

    vsftp怎么用_c++ ftp一、vsftp以及安装服务端软件:vsftpd客户端软件:ftp端口号:20、21或指定范围内其他随机端口配置文件:vim/etc/vsftpd/vsftpd.conf#安装yuminstallvsftpdftp#开机自启systemctlenablevsftpd#启动systemctlstartvsftpd#查看端口开放情况netstat-antp二、工作模式,默认是主动port模式①主动模式(prot):FTP.

    2022年9月24日
    1
  • NFV介绍_NFV技术

    NFV介绍_NFV技术转发自:https://zhuanlan.zhihu.com/p/26259440NFV全称是NetworkFunctionVirtualization。这又是一个与网络相关的故事。先来看看NFV的前世今生吧。在NFV之前,NF(NetworkFunction)是一直存在的,网络中,NF可以看成一个个独立的网元,实现着各自的功能。NF以固定的方式连接起来,统一提供的网络功能和服务。随便在网…

    2022年9月10日
    4
  • linux修改用户密码命令_linux更改用户密码的命令

    linux修改用户密码命令_linux更改用户密码的命令Linux修改用户密码使用的Linux版本是:ubuntu-18.10-live-server-amd64知道一个用户名密码时,修改用户密码,各个版本下都是通用的;重置密码的时候,版本不同,可能操作的地方不一样了。如果一个账号的密码都不记得了(这通常是需要修改用户密码最多的情况),那就需要重置密码,相对就比较复杂一些,放在最后讲。但凡知道一个用户的密码,那就好办。(普通用户登录的情况下,也可以修改root用户的密码。)1.知道一个账号的密码这就是正常情况下,修改用户密码。1.1知道roo

    2022年9月6日
    6
  • 树莓派4b支持5gwifi吗_树莓派4和4b的区别

    树莓派4b支持5gwifi吗_树莓派4和4b的区别树莓派4b与Manjaro,安装、配置、修复WiFi频段5G和CountryCode安装Manjaro到树莓派4b下载Manjaro烧录系统到SD卡并启动修复无线网络5G频段更新软件仓库安装缺失的功能安装Manjaro到树莓派4bManjaroLinux(或简称Manjaro)是基于ArchLinux的Linux发行版,使用Xfce、GNOME和KDEPlasma作为默认桌面环境,和Arch一样,采用滚动更新。其目标是为PC提供易于使用的自由的操作系统。Manjaro

    2022年10月20日
    2
  • java线程池springboot_springboot线程池的使用和扩展(转)「建议收藏」

    java线程池springboot_springboot线程池的使用和扩展(转)「建议收藏」实战环境windowns10;jdk1.8;springboot1.5.9.RELEASE;开发工具:IntelliJIDEA;实战源码本次实战的源码可以在我的GitHub下载,地址:git@github.com:zq2599/blog_demos.git,项目主页:https://github.com/zq2599/blog_demos这里面有多个工程,本次用到的工程为threadpoold…

    2022年6月17日
    85

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号