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


相关推荐

  • iOS UIWebView获取当前JSContext

    iOS UIWebView获取当前JSContext

    2021年9月15日
    75
  • sntp 校时问题

    sntp 校时问题1 背景由于项目中的数据对时间比较敏感 目前常常出现校时问题 导致时间偏差 出现曲线数据丢失和曲线数据重复等问题 因此对 sntp 源码进行深入分析 要了解 SNTP 首先需要了解 NTP 协议 SNTP 是 NTP 的子集 简化了 NTP 的许多算法和步骤 得到了效率 但时间的精度不如 NTP 可是对于民用时间来说足够了 大概最多差距几秒的样子 NTP NetworkTimeP 网络时间协议 是由 RFC1305 定义的时间同步协议 用来在分布式时间服务器和客户端之间进行时间同步 NTP 基于 UDP 报

    2025年6月20日
    4
  • 一生要看的50部经典电影

    一生要看的50部经典电影

    2021年5月4日
    165
  • SaveFileDialog无法打开

    SaveFileDialog无法打开在线程中SaveFileDialog无法打开。Threadt=newThread(saveDialog);t.IsBackground=true;t.SetApartmentState(ApartmentState.STA);//加上这句就可以了t.Start();当前画面是报表画面,没用线程。主画面点击按钮,打开该画面,是在子线程中打开的,所以SaveFileDialog也无法直接打开…

    2022年10月8日
    3
  • 可以搜课程设计的网站_课程设计论文格式

    可以搜课程设计的网站_课程设计论文格式1.主要功能:展示各种类型的作文。普通用户的登录注册和管理员用户登录。可以精确或模糊按照作文题目搜索。还有分页功能,首页、尾页、上一页、下一页。返回顶部等等很多功能。普通用户登录:发表作文,管理自己的作文,管理自己账号。管理员用户登录:发表作文,管理所有的作文,管理所有账号。数据库用的是sqlserver。丰富精美的css、js效果。2.效果截图:登录/注册没登录时的基础首页普通用户:左边的侧边栏可以随意显示隐藏。管理员:3.项目文件截图:

    2025年6月14日
    5
  • 用 CSS 隐藏页面元素

    用 CSS 隐藏页面元素用 CSS 隐藏页面元素

    2022年4月24日
    49

发表回复

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

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