广告
返回顶部
首页 > 资讯 > 后端开发 > Python >开源组件:(3)dbutils
  • 106
分享到

开源组件:(3)dbutils

开源组件dbutils 2023-01-31 07:01:57 106人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

commons-dbutils 是 Apache 组织提供的一个开源JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影响程序的性能。因此dbutils成为很多不喜欢

commons-dbutils 是 Apache 组织提供的一个开源JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影响程序的性能。因此dbutils成为很多不喜欢hibernate的公司的首选。

DbUtils组件的主要作用是简化jdbc操作。

项目准备

1. 引入Mysql驱动:mysql-connector-java-5.1.38-bin.jar

2. 引入jar文件 : commons-dbutils-1.6.jar

下载dbutils组件: Http://commons.apache.org/proper/commons-dbutils/download_dbutils.cgi



DbUtils类的主要作用是:关闭资源、加载驱动。


QueryRunner类,位于org.apache.commons.dbutils包下,全名org.apache.commons.dbutils.QueryRunner


QueryRunner类是组件的核心工具类:定义了所有的与数据库操作的方法(查询、更新)

对于QueryRunner类的描述是Executes sql queries with pluggable strategies for handling ResultSets. This class is thread safe.


下面的话,要多读几遍:

【Executes SQL queries】 with 【pluggable strategies】 for 【handling ResultSets】.


QueryRunner类提供了默认的构造函数:public QueryRunner() ,在进行update、query等方式法需要传入Connection对象


QueryRunner类还提供了另外一个构造函数,接受DataSource类型的对象:public QueryRunner(DataSource ds) 

对这个构造函数的描述是:Constructor for QueryRunner that takes a DataSource to use. Methods that do not take a Connection parameter will retrieve connections from this DataSource.使用不带Connnection参数的方法时,将从DataSource中获取Connection对象。


提供的update方法(带有Connection)

(1)public int update(Connection conn, String sql)

//描述:Execute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.

(2)public int update(Connection conn, String sql, Object param) 

//描述:Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.

(3)public int update(Connection conn, String sql, Object... params)

//描述:Execute an SQL INSERT, UPDATE, or DELETE query.



提供的update方法(不带有Connection)

(1)public int update(String sql)

//描述:Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.

(2)public int update(String sql, Object param)

//描述:Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.

(3)public int update(String sql, Object... params)

//描述:Executes the given INSERT, UPDATE, or DELETE SQL statement. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.



提供的query方法(带Connection对象)

(1)public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh)

//描述:Execute an SQL SELECT query without any replacement parameters. The caller is responsible for closing the connection.

(2)public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh, Object... params) 

//描述:Execute an SQL SELECT query with replacement parameters. The caller is responsible for closing the connection.



提供的query方法(不带有Connection)

(1)public <T> T query(String sql, ResultSetHandler<T> rsh)

//描述:Executes the given SELECT SQL without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor.

(2)public <T> T query(String sql, ResultSetHandler<T> rsh, Object... params)

//描述:Executes the given SELECT SQL query and returns a result object. The Connection is retrieved from the DataSource set in the constructor.


2.1、更新

执行一次

package com.rk.demo;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;

import com.rk.utils.JDBCUtils;

//1. 更新
public class Demo01
{
	public static void main(String[] args)
	{
		Connection conn = null;
		try
		{
			//SQL语句
			String sql = "INSERT INTO T_Dogs(Name,Age,BirthDay) VALUES(?,?,?)";
			// 获取连接对象
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			//执行新增操作
			qr.update(conn, sql, "旺财","2","2015-08-08");
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			// 关闭
			DbUtils.closeQuietly(conn);
		}
	}
}

批处理

package com.rk.demo;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;

import com.rk.utils.JDBCUtils;

//2. 批处理
public class Demo02
{
	public static void main(String[] args)
	{
		Connection conn = null;
		try
		{
			//SQL语句
			String sql = "INSERT INTO T_Dogs(Name,Age,BirthDay) VALUES(?,?,?)";
			// 获取连接对象
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 执行批量新增
			qr.batch(conn, sql, new Object[][]{{"小狗1","1","2015-08-09"},{"小狗2","1","2015-08-10"}});
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
}


2.2、查询

1.自定义结果封装数据(自己写代码实现)

package com.rk.demo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFORMat;
import java.util.Date;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import com.rk.entity.DogInfo;
import com.rk.utils.JDBCUtils;
//1.查询, 自定义结果集封装数据
public class Demo03
{
	public static void main(String[] args)
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT * FROM T_Dogs WHERE Id=?";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			DogInfo dog = qr.query(conn,sql, new ResultSetHandler<DogInfo>(){
				// 如何封装一个DogInfo对象
				@Override
				public DogInfo handle(ResultSet rs) throws SQLException
				{
					DogInfo dog = null;
					if (rs.next())
					{
						dog = new DogInfo();
						dog.setId(rs.getInt("Id"));
						dog.setName(rs.getString("Name"));
						dog.setAge(rs.getInt("Age"));
						String strBirthDay = rs.getDate("BirthDay").toString();
						Date birthDay = null;
						try
						{
							SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
							birthDay = sdf.parse(strBirthDay);
						}
						catch (ParseException e)
						{
							e.printStackTrace();
						}
						dog.setBirthDay(birthDay);
					}
					return dog;
				}}, 2);
			// 打印输出结果
			System.out.println(dog);
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			//关闭Connection对象
			DbUtils.closeQuietly(conn);
		}
	}
}


2.使用BeanHandler、BeanListHandler和ScalarHandler

package com.rk.demo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.junit.Test;

import com.rk.entity.DogInfo;
import com.rk.utils.JDBCUtils;

//2.查询, 使用组件提供的结果集对象封装数据
public class Demo04
{
	@Test
	// 1)BeanHandler: 查询返回单个对象
	public void testBeanHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT * FROM T_Dogs WHERE Id=?";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询返回单个对象
			DogInfo dog = qr.query(conn,sql, new BeanHandler<DogInfo>(DogInfo.class), 2);
			//打印结果
			System.out.println(dog);
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	// 2)BeanListHandler: 查询返回list集合,集合元素是指定的对象
	public void testBeanListHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT * FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询全部数据
			List<DogInfo> list = qr.query(conn,sql, new BeanListHandler<DogInfo>(DogInfo.class));
			//打印结果
			for(DogInfo dog : list)
			{
				System.out.println(dog);
			}
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	// 3)ScalarHandler: 查询返回指定“列名”或“索引”的值
	public void testScalarHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT count(*) FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询数量
			Long count = qr.query(conn,sql, new ScalarHandler<Long>(1));//索引从1开始
			//打印结果
			System.out.println("共有"+count.intValue()+"个记录");
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
}


3.使用其它的ResultSetHandler

package com.rk.demo;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayHandler;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.BeanMapHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.KeyedHandler;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.junit.Test;

import com.rk.entity.DogInfo;
import com.rk.utils.JDBCUtils;

public class Demo05
{
	@Test
	//ArrayHandler返回的是一个Object[]对象,其中是同一条记录中各个列的值,如[3, 汪汪, 2, 2016-06-08]
	public void testArrayHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT * FROM T_Dogs WHERE Id=?";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			Object[] objs = qr.query(conn,sql, new ArrayHandler(), 3);
			//打印结果
			System.out.println(Arrays.toString(objs));
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//ArrayListHandler返回的是List<Object[]>对象
	public void testArrayListHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT * FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			List<Object[]> list = qr.query(conn,sql, new ArrayListHandler());
			//打印结果
			for(Object[] dog : list)
			{
				System.out.println(Arrays.toString(dog));
			}
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//BeanMapHandler: Creates a new instance of BeanMapHandler. The value of the first column of each row will be a key in the Map.
	public void testBeanMapHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT Name,Age,BirthDay FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			Map<String, DogInfo> map = qr.query(conn,sql, new BeanMapHandler<String, DogInfo>(DogInfo.class));
			//打印结果
			for(Map.Entry<String,DogInfo> item : map.entrySet())
			{
				System.out.println(item.geTKEy() + ":" + item.getValue());
			}
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//ColumnListHandler: Converts one ResultSet column into a List of Objects.
	public void testColumnListHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT Name,Age,BirthDay FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			List<String> list = qr.query(conn,sql, new ColumnListHandler<String>(1));
			//打印结果
			for(String item : list)
			{
				System.out.println(item);
			}
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//KeyedHandler: Returns a Map of Maps. ResultSet rows are converted into Maps which are then stored in a Map under the given key.
	public void testKeyedHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT Id, Name,Age,BirthDay FROM T_Dogs";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			Map<String, Map<String, Object>> map = qr.query(conn,sql, new KeyedHandler<String>("Name"));
			Map<String, Object> wcMap = map.get("旺财");
			//打印结果
			System.out.println(wcMap.get("Id"));
			System.out.println(wcMap.get("Name"));
			System.out.println(wcMap.get("Age"));
			System.out.println(wcMap.get("BirthDay"));
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//MapHandler: 将一条记录以Key/Value的形式保存于Map中,Key中值就是Column的值
	public void testMapHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT Id, Name,Age,BirthDay FROM T_Dogs WHERE Id=?";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			Map<String, Object> map = qr.query(conn,sql, new MapHandler(),3);
			//打印结果
			for(Map.Entry<String,Object> item : map.entrySet())
			{
				System.out.println(item.getKey() + ":" + item.getValue());
			}
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
	
	@Test
	//MapListHandler
	public void testMapListHandler()
	{
		Connection conn = null;
		try
		{
			String sql = "SELECT Id, Name,Age,BirthDay FROM T_Dogs WHERE Id";
			// 获取连接
			conn = JDBCUtils.getConnection();
			// 创建DbUtils核心工具类对象
			QueryRunner qr = new QueryRunner();
			// 查询
			List<Map<String, Object>> list = qr.query(conn,sql, new MapListHandler());
			//打印结果
			for(Map<String, Object> map : list)
			{
				for(Map.Entry<String,Object> item : map.entrySet())
				{
					System.out.print(item.getKey() + ":" + item.getValue() + "\t");
				}
				System.out.println();
			}
			
			
		}
		catch (SQLException e)
		{
			throw new RuntimeException(e);
		}
		finally
		{
			DbUtils.closeQuietly(conn);
		}
	}
}




3.1、DbUtils类源码

DbUtils类,位于org.apache.commons.dbutils包下,全名org.apache.commons.dbutils.DbUtils

DbUtils类的主要作用是:关闭资源、加载驱动

DbUtils类的部分源码:


package org.apache.commons.dbutils;

import static java.sql.DriverManager.reGISterDriver;

import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.util.logging.Logger;
import java.util.Properties;


public final class DbUtils {

    
    public DbUtils() {
        // do nothing
    }

    
    public static void close(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }

    
    public static void close(ResultSet rs) throws SQLException {
        if (rs != null) {
            rs.close();
        }
    }

    
    public static void close(Statement stmt) throws SQLException {
        if (stmt != null) {
            stmt.close();
        }
    }

    
    public static void closeQuietly(Connection conn) {
        try {
            close(conn);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    
    public static void closeQuietly(Connection conn, Statement stmt,
            ResultSet rs) {

        try {
            closeQuietly(rs);
        } finally {
            try {
                closeQuietly(stmt);
            } finally {
                closeQuietly(conn);
            }
        }

    }

    
    public static void closeQuietly(ResultSet rs) {
        try {
            close(rs);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    
    public static void closeQuietly(Statement stmt) {
        try {
            close(stmt);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    
    public static void commitAndClose(Connection conn) throws SQLException {
        if (conn != null) {
            try {
                conn.commit();
            } finally {
                conn.close();
            }
        }
    }

    
    public static void commitAndCloseQuietly(Connection conn) {
        try {
            commitAndClose(conn);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    
    public static boolean loadDriver(String driverClassName) {
        return loadDriver(DbUtils.class.getClassLoader(), driverClassName);
    }

    
    public static boolean loadDriver(ClassLoader classLoader, String driverClassName) {
        try {
            Class<?> loadedClass = classLoader.loadClass(driverClassName);

            if (!Driver.class.isAssignableFrom(loadedClass)) {
                return false;
            }

            @SuppressWarnings("unchecked") // guarded by previous check
            Class<Driver> driverClass = (Class<Driver>) loadedClass;
            Constructor<Driver> driverConstructor = driverClass.getConstructor();

            // make Constructor accessible if it is private
            boolean isConstructorAccessible = driverConstructor.isAccessible();
            if (!isConstructorAccessible) {
                driverConstructor.setAccessible(true);
            }

            try {
                Driver driver = driverConstructor.newInstance();
                registerDriver(new DriverProxy(driver));
            } finally {
                driverConstructor.setAccessible(isConstructorAccessible);
            }

            return true;
        } catch (RuntimeException e) {
            return false;
        } catch (Exception e) {
            return false;
        }
    }


    
    public static void rollback(Connection conn) throws SQLException {
        if (conn != null) {
            conn.rollback();
        }
    }

    
    public static void rollbackAndClose(Connection conn) throws SQLException {
        if (conn != null) {
            try {
                conn.rollback();
            } finally {
                conn.close();
            }
        }
    }

    
    public static void rollbackAndCloseQuietly(Connection conn) {
        try {
            rollbackAndClose(conn);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

}


3.2、QueryRunner类源码

update部分的源码

所有public修饰的update方法都会调用丰面这个方法。注意第二个参数boolean closeConn

private int update(Connection conn, boolean closeConn, String sql, Object... params)


   
    public int update(Connection conn, String sql) throws SQLException {
        return this.update(conn, false, sql, (Object[]) null);
    }

    
    public int update(Connection conn, String sql, Object param) throws SQLException {
        return this.update(conn, false, sql, new Object[]{param});
    }

    
    public int update(Connection conn, String sql, Object... params) throws SQLException {
        return update(conn, false, sql, params);
    }

    
    public int update(String sql) throws SQLException {
        Connection conn = this.prepareConnection();

        return this.update(conn, true, sql, (Object[]) null);
    }

    
    public int update(String sql, Object param) throws SQLException {
        Connection conn = this.prepareConnection();

        return this.update(conn, true, sql, new Object[]{param});
    }

    
    public int update(String sql, Object... params) throws SQLException {
        Connection conn = this.prepareConnection();

        return this.update(conn, true, sql, params);
    }

    
    private int update(Connection conn, boolean closeConn, String sql, Object... params) throws SQLException {
        if (conn == null) {
            throw new SQLException("Null connection");
        }

        if (sql == null) {
            if (closeConn) {
                close(conn);
            }
            throw new SQLException("Null SQL statement");
        }

        PreparedStatement stmt = null;
        int rows = 0;

        try {
            stmt = this.prepareStatement(conn, sql);
            this.fillStatement(stmt, params);
            rows = stmt.executeUpdate();

        } catch (SQLException e) {
            this.rethrow(e, sql, params);

        } finally {
            close(stmt);
            if (closeConn) {
                close(conn);
            }
        }

        return rows;
    }


query部分的源码

所有的public修饰的query方法都会调用下面的方法。注意第二个参数boolean closeConn

private <T> T query(Connection conn, boolean closeConn, String sql, ResultSetHandler<T> rsh, Object... params)


    
    public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh, Object... params) throws SQLException {
        return this.<T>query(conn, false, sql, rsh, params);
    }

    
    public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh) throws SQLException {
        return this.<T>query(conn, false, sql, rsh, (Object[]) null);
    }

    
    public <T> T query(String sql, ResultSetHandler<T> rsh, Object... params) throws SQLException {
        Connection conn = this.prepareConnection();

        return this.<T>query(conn, true, sql, rsh, params);
    }

    
    public <T> T query(String sql, ResultSetHandler<T> rsh) throws SQLException {
        Connection conn = this.prepareConnection();

        return this.<T>query(conn, true, sql, rsh, (Object[]) null);
    }

    
    private <T> T query(Connection conn, boolean closeConn, String sql, ResultSetHandler<T> rsh, Object... params)
            throws SQLException {
        if (conn == null) {
            throw new SQLException("Null connection");
        }

        if (sql == null) {
            if (closeConn) {
                close(conn);
            }
            throw new SQLException("Null SQL statement");
        }

        if (rsh == null) {
            if (closeConn) {
                close(conn);
            }
            throw new SQLException("Null ResultSetHandler");
        }

        PreparedStatement stmt = null;
        ResultSet rs = null;
        T result = null;

        try {
            stmt = this.prepareStatement(conn, sql);
            this.fillStatement(stmt, params);
            rs = this.wrap(stmt.executeQuery());
            result = rsh.handle(rs);

        } catch (SQLException e) {
            this.rethrow(e, sql, params);

        } finally {
            try {
                close(rs);
            } finally {
                close(stmt);
                if (closeConn) {
                    close(conn);
                }
            }
        }

        return result;
    }





--结束END--

本文标题: 开源组件:(3)dbutils

本文链接: https://www.lsjlt.com/news/191141.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 开源组件:(3)dbutils
    commons-dbutils 是 Apache 组织提供的一个开源JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影响程序的性能。因此dbutils成为很多不喜欢...
    99+
    2023-01-31
    开源 组件 dbutils
  • Android开源组件小结
    前言       Android自带的组件比较丑陋(个人感觉),自己写组件比较复杂,而且必须熟悉android应用层开发的一些...
    99+
    2022-06-06
    小结 Android
  • 开源组件:(1)DBCP和C3P0
    一种技术的出现,要么是解决实际问题,要么是优化现有技术。数据库连接池技术的出现,是为了优化数据库连接操作的性能。在使用JDBC进行数据库开发的时候,一般经历这样一个过程:1)加载数据库的驱动2)建立数据库的...
    99+
    2022-10-18
  • jQuery开源组件BootstrapValidator怎么用
    这篇文章主要介绍了jQuery开源组件BootstrapValidator怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。具体内容如下表...
    99+
    2022-10-19
  • openstack的3大组件
    OpenStack旗下包含了一组由社区维护的开源项目,他们分别是OpenStackCompute(Nova)OpenStackObjectStorage(Swift) OpenStackImageService(Glance)。Nova,为...
    99+
    2023-01-31
    组件 openstack
  • Flex中FlexReport开源组件如何使用
    这期内容当中小编将会给大家带来有关Flex中FlexReport开源组件如何使用,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。Flex中FlexReport开源组件用法FlexReport开源组件是基于L...
    99+
    2023-06-17
  • 开源日志记录组件Log4Net怎么用
    这篇文章主要介绍了开源日志记录组件Log4Net怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。log4net是.Net下一个非常优秀的开源日志记录组件。log4net记...
    99+
    2023-06-03
  • Vite + React从零开始搭建一个开源组件库
    目录前言目标搭建开发环境️生成模板CSS预处理器eslint组件库编译⚡️vite的打包配置⚡️自动生成ts类型文件⚡️样式懒加载与全量加载文档❤️npm 发布与发布前的测试测试前言...
    99+
    2022-11-13
  • vue3新拟态组件库开发流程之table组件源码分析
    目录基础表格固定表头高度/流体高度自定义列宽基础表格 首先开发table组件之前,先想好要用什么样式的api,因为笔者在生产工作中用的都是element,所以前面几个组件风格和ele...
    99+
    2023-05-18
    vue3 table组件源码 vue3组件库开发
  • .NET 开源配置组件 AgileConfig的使用简介
    目录介绍架构图部署服务端在客户端程序使用总结介绍 在微服务大行其道的今天,系统会被拆分成多个模块,作为单独的服务运行,同时为了集中化管理,我们还需要日志中心,配置中心等,很多开发人...
    99+
    2022-11-12
  • Flex开源组件怎么显示各种文档
    这篇文章给大家分享的是有关Flex开源组件怎么显示各种文档的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。Flex开源组件显示各种文档教程FlexPaper是一个开源轻量级的在浏览器上显示各种文档的组件,被设计用来...
    99+
    2023-06-17
  • 鸿蒙开源第三方组件之连续滚动图像组件功能
    目录前言背景组件效果展示Sample解析Library解析前言 基于安卓平台的连续滚动图像组件ContinuousScrollableImageView(https://github...
    99+
    2022-11-12
  • XamarinAndroid组件教程RecylerView动画组件使用动画(3)
    XamarinAndroid组件教程RecylerView动画组件使用动画(3)(8)打开Main.axml文件,构建主界面。代码如下:<xml version="1.0" encoding="utf-8"><Linear...
    99+
    2023-06-05
  • Android开源组件SlidingMenu侧滑菜单使用介绍
    现在很多android应用都有侧滑菜单,效果很不错。 GitHub上有SlidingMenu的开源库,使用起来很方便。 SlidingMenu GitHub地址:https:/...
    99+
    2022-06-06
    菜单 slidingmenu Android
  • 开源软件许可
    因为日常工作中用到了,一些开源的产品,每个产品说明中,会有一些开源许可的介绍,各种名字,不很理解其中的含义。据资料记载,开源软件的许可有上百种,但最流行的只有6种,即GPL、LGPL、Mozilla、BSD、MIT和Apache,其他的可以...
    99+
    2023-06-02
  • 怎么使用Vite+React搭建一个开源组件库
    今天小编给大家分享一下怎么使用Vite+React搭建一个开源组件库的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。目标开发环...
    99+
    2023-07-02
  • Vue中子组件调用父组件的3种方法实例
    目录1.直接在子组件中通过“this.$parent.event”来调用父组件的方法。2.子组件用“$emit”向父组件触发一个事件,...
    99+
    2022-11-13
  • ExtJS(3)- 自定义组件(星级评分
        今天介绍ExtJS的组件开发,这里以星级评分为示例,首先来看看效果图:    然后是功能操作:鼠标移动到五个星星上面时,会有tooltip显示当前的分值。如图:鼠标悬停在第四颗星星时前四颗星星显示高亮笑脸,当点击下去时锁定笑脸并且设...
    99+
    2023-01-31
    星级 自定义 组件
  • iOS组件化源码分析
    这篇“iOS组件化源码分析”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“iOS组件化源码分析”文章吧。一、iOS 组件化常用...
    99+
    2023-07-05
  • Android学习笔记(Android Studio)3-2(AlertDialog)UI组件之弹出组件
    Android学习笔记3-2 推荐新手向学习视频:B站https://www.bilibili.com/video/av38409964点我传...
    99+
    2022-06-06
    android学习 Android Studio studio alertdialog Android
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作