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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 动态规划经典题目汇总图_离散型动态规划经典题目

    动态规划经典题目汇总图_离散型动态规划经典题目http://www.cppblog.com/doer-xee/archive/2009/12/05/102629.html转载之前先Orz一下:[s:19]Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总

    2025年7月9日
    2
  • 谷歌搜索引擎使用语法大全收集软件_搜索引擎语法

    谷歌搜索引擎使用语法大全收集软件_搜索引擎语法目录google介绍关于谷歌语法的一些例子Google常用语法踩点:需要收集的十个方面Google的一些入口地址谷歌语法详解需要注意以下几点:详细描述看以下几条链接:最后总结一下:看图片更直观GoogleHack技术是现在最火暴的黑客技术之一。其原理很简单,就是利用搜索引擎强大的搜索能力,来查找一些存在漏洞的网站。要利用Google来查找网站的漏洞自然要学会Google这个搜索引擎的语法了。下…

    2025年10月22日
    4
  • Graphics2D 绘制图形

    Java语言在Graphics类提供绘制各种基本的几何图形的基础上,扩展Graphics类提供一个Graphics2D类,它拥用更强大的二维图形处理能力,提供、坐标转换、颜色管理以及文字布局等更精确的控制。绘图属性Graphics2D定义了几种方法,用于添加或改变图形的状态属性。可以通过设定和修改状态属性,指定画笔宽度和画笔的连接方式;设定平移、旋转、缩放或修剪变换图形;以及设定填充图

    2022年4月13日
    102
  • 这些最常用的Linux命令,每一条都应该学会!

    点击上方“全栈程序员社区”,星标公众号 重磅干货,第一时间送达 作者:陈良 cnblogs.com/chenliangchaoshuai/p/11827383.html linux…

    2021年6月27日
    113
  • ARM指令中LDR与MOV的区别与应用——看这一篇就够了

    ARM指令中LDR与MOV的区别与应用——看这一篇就够了ARM指令中LDR与MOV的区别与应用、从内存中寻址的方法、LDR伪指令和MOV指令的异同

    2022年6月17日
    28
  • python判断是否为空_python 判断对象是否为空

    python判断是否为空_python 判断对象是否为空在实际的工作当中,我们难免要与空值打交道,相信不少初学者都会写出下面的代码:ifaisNone:dosomething.else:dotheotherthing.python学习网,大量的免费python视频教程,欢迎在线学习!这样写看起来不错,但实际上会有问题。一般来讲,Python中会把下面几种情况当做空值来处理:NoneFalse0,0.0,0L”,(),[],{}其中Non…

    2022年6月12日
    166

发表回复

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

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