您的位置:首页 > 运维架构 > Apache

apache-comnons系列之commons-dbutils1.7 学习笔记

2017-07-26 00:17 483 查看

apache-comnons系列之commons-dbutils1.7 学习笔记

概述

参考

http://blog.csdn.net/imust_can/article/details/7005972

DbUtils

A collection of JDBC helper methods. This class is thread safe.

QueryRunner

Executes SQL queries with pluggable strategies for handling
ResultSet
s. This class is thread safe

QueryLoader

QueryLoader
is a registry for sets of queries so that multiple copies of the same queries aren’t loaded into memory.

This implementation loads properties files filled with query name to SQL mappings. This class is thread safe.

ResultSetHandler

Implementations of this interface convert ResultSets into other objects.

org.apache.commons.dbutils.handlers.ArrayHandler

return rs.next() ? this.convert.toArray(rs) : EMPTY_ARRAY;

org.apache.commons.dbutils.handlers.BeanListHandler

ResultSetHandler implementation that converts a
ResultSet
into a
List
of beans. This class is thread safe.

org.apache.commons.dbutils.handlers.MapHandler

ResultSetHandler
implementation that converts the first
ResultSet
row into a
Map
. This class is thread

RowProcessor

RowProcessor implementations convert
ResultSet
rows into various other objects. Implementations can extend
BasicRowProcessor
to protect themselves from changes to this interface

BasicRowProcessor

toArray

toBean

toMap

ColumnHandler

Interface to define how implementations can interact with column handling when constructing a bean from a{@link java.sql.ResultSet}. ColumnHandlers do the work of retrieving data correctly from the
ResultSet
.

match

apply

StringTrimmedResultSet

Wraps a
ResultSet
to trim strings returned by the
getString()
and
getObject()
methods.

type.cast(Proxy.newProxyInstance(handler.getClass().getClassLoader(), new Class

测试

org.apache.commons.dbutils.DbUtilsTest

closeQuietly

Close a
Connection
,
Statement
and
ResultSet
. Avoid closing if null and hide any SQLExceptions that occur.

commitAndCloseQuietly

Commits a
Connection
then closes it, avoid closing if null and hide any SQLExceptions that occur

rollbackAndCloseQuietly

Performs a rollback on the
Connection
then closes it,avoid closing if null and hide any SQLExceptions that occur

loadDriver

Loads and registers a database driver class.If this succeeds, it returns true, else it returns false

org.apache.commons.dbutils.QueryRunnerTest

query

Calls query after checking the parameters to ensure nothing is null.

update

Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter

insert

Executes the given INSERT SQL statement.

org.apache.commons.dbutils.QueryLoaderTest

load

Loads a Map of query names to SQL values. The Maps are cached so a

subsequent request to load queries from the same path will return

the cached Map. The properties file to load can be in either

line-oriented or XML format. XML formatted properties files must use a

.xml
file extension
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java dbutils apache jdbc