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/168962.html原文链接:https://javaforall.net

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


相关推荐

  • python 递归深度

    python 递归深度python对于递归深度有默认的设置,当递归层数过深,超过1000时,会报错RecursionError:maximumrecursiondepthexceededwhilecallingaPythonobject可以通过如下设置:importsyssys.setrecursionlimit(1200)手动设置递归深度,测试后发现,最大上限在8

    2022年6月22日
    69
  • hdu2544_GB4278

    hdu2544_GB4278HDU 4278 Faulty Odometer

    2022年4月21日
    53
  • siamfc运行_sta系统

    siamfc运行_sta系统修改siamfc文件夹下的Load.py文件importsyssys.path.append(‘/home/nanorobot/Documents/siamfc/siamfc’)sys.path.append(‘/home/nanorobot/Documents/siamfc’)fromsiamfcimportTrackerSiamFC,ops上面是把需要用到的自定义的模块路径引入进来,以防后面找不到模块,路径根据你自己的文件位置改。下面是修改主函数:if__name__==

    2022年10月1日
    4
  • sstream读取文件

    sstream读取文件对于如下图所示的数据文件:274表示有274个点对,以下每一行代表一个点对,每一行的四个数从左到右依次是一个第一个点的x坐标、y坐标、第二个点的x坐标、y坐标,现在要把点对数和每个点对读取并存储,具体代码如下:#include<iostream>#include<sstream>#include<fstream>#include<string&…

    2022年6月4日
    48
  • SQL Server数据库分区分表

    SQL Server数据库分区分表当一个数据表的数据量达到千万级别以后,每次查询都需要消耗大量的时间,所以当表数据量达到一定量级后我们需要对数据表水平切割。水平分区分表就是把逻辑上的一个表,在物理上按照你指定的规则分放到不同的文件里,把一个大的数据文件拆分为多个小文件,还可以把这些小文件放在不同的磁盘下。这样把一个大的文件拆分成多个小文件,便于我们对数据的管理。下面我们来创建表分区代码创建分区表添加文件组代码格式:…

    2022年6月5日
    69
  • 放单平台_自媒体哪个平台好

    放单平台_自媒体哪个平台好Iamdoingaclustertest,whydidIencounterthelderrorwhencompilingtheseveralpackagesfrom/home/builder/master/master50/master_eXtremeDB_4.0.1780_linux/packs_x64.Theerrorinfoisbelow:ly@l…

    2022年10月15日
    3

发表回复

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

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