jdbc fetchsize_jdbc和odbc的关系

jdbc fetchsize_jdbc和odbc的关系DBUtilscommons-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/168938.html原文链接:https://javaforall.net

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


相关推荐

  • HTML DOM clearInterval() 方法

    HTML DOM clearInterval() 方法

    2021年10月18日
    53
  • 京东-n头熊分苹果「建议收藏」

    京东-n头熊分苹果「建议收藏」果园里有一堆苹果,一共n头(n大于1小于9)熊来分,第一头为小东,它把苹果均分n份后,多出了一个,它扔掉了这一个,拿走了自己的一份苹果,接着第二头熊重复这一过程,即先均分n份,扔掉一个然后拿走一份,以此类推直到最后一头熊都是这样(最后一头熊扔掉后可以拿走0个,也算是n份均分)。问最初这堆苹果最少有多少个。给定一个整数n,表示熊的个数,返回最初的苹果数。保证有解。测试样例:2返回:3

    2022年10月12日
    2
  • EasyPlayer支持YUV数据导出功能

    EasyPlayer支持YUV数据导出功能我们可能会遇到这样的功能,播放一个视频的同时,再把这个视频推送出去,或者对视频数据进行智能分析等处理.这样我们就迫切需要得到视频的原始数据.基于这个需求,EasyPlayer增加了获取视频YUV数据的功能.它的原理是这样的:CreatedwithRaphaël2.1.2EasyPlayerClientEasyPlayerClientDecoderDecoderYUVYUV读取媒体…

    2022年6月25日
    26
  • Mac下SVN基本操作和常见错误

    Mac下SVN基本操作和常见错误

    2021年10月20日
    44
  • ROS中cv_bridge如何用python3进行编译

    ROS中cv_bridge如何用python3进行编译最近遇到了个问题,cv_bridge实现了opencv和ros中图像数据类型的转换,但ros-melodic默认python版本是python2。在配置yolact环境的时候,要求是python3。这就导致在ros自带的cv_bridge是python2版本,想使用python3的话需要自己去编译cv_bridge。否则会报错:ImportError:dynamicmoduledoesnotdefinemoduleexportfunction(PyInit_cv_bridge_boo

    2022年5月27日
    36
  • CornerRadius圆角属性[通俗易懂]

    CornerRadius圆角属性[通俗易懂]CornerRadius是Border、Rectangle等控件的圆角属性,其值含义如下:CornerRadius="左上,右上,右下,左下"

    2022年7月2日
    39

发表回复

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

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