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


相关推荐

  • 计算机信息计量单位kgm,工程单位换算表.pdf

    计算机信息计量单位kgm,工程单位换算表.pdf工程单位换算表流量计|论文|工程单位换算表流量计:蒸汽流量计|污水流量计|明渠式流量计|电磁流量计|靶式流量计|涡街|涡轮|流量积算仪产品信息样本下载调查问卷论坛留言关于我们产品价格招聘买马技术资料…

    2022年5月14日
    77
  • Windows11安装 Python

    Windows11安装 PythonWindow11安装Python

    2025年8月7日
    2
  • 彩色图和深度图转点云

    彩色图和深度图转点云环境:windows10、VS2013、opencv2.49、openNi、PCL1.8opencv环境搭建参考https://www.cnblogs.com/cuteshongshong/p/4057193.htmlhttps://blog.csdn.net/u013105549/article/details/50493069PCL1.8+openNi搭建参考https://blog.cs…

    2022年4月25日
    40
  • H2数据库相关介绍「建议收藏」

    H2数据库相关介绍「建议收藏」什么是H2数据库H2是一个开源的嵌入式数据库引擎,采用java语言编写,不受平台的限制,同时H2提供了一个十分方便的web控制台用于操作和管理数据库内容。H2还提供兼容模式,可以兼容一些主流的数据库,因此采用H2作为开发期的数据库非常方便。H2是纯java编写的,源码大小只有1M左右。优点:速度非常快,开源,JDBCAPI嵌入式和服务器模式;内存数据库基于浏览器的Console应用…

    2022年10月12日
    4
  • python win32api中文手册_python 模拟鼠标和键盘输入

    python win32api中文手册_python 模拟鼠标和键盘输入importwin32guiimportwin32conimportwin32api#从顶层窗口向下搜索主窗口,无法搜索子窗口#FindWindow(lpClassName=None,lpWindowName=None)窗口类名窗口标题名handle=win32gui.FindWindow(“Notepad”,None)#获取窗口位置left,top,right,bo…

    2022年10月11日
    4
  • ant的安装和使用

    ant的安装和使用1.ant的安装1.1添加环境变量:ANT_HOME=D:\software\ant\apache-ant-1.10.1在path中添加:%ANT_HOME%\bin1.2测试是否安装成功

    2022年7月1日
    18

发表回复

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

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