麻雀 DbUtils

http://commons.apache.org/dbutils/

这个程序很小,但是也是apache的一个开源项目,从这么个小项目看看高手是如何把代码写得熨帖的。

 

Commons DbUtils: JDBC Utility Component

DbUtils is a small set of classes designed to make working with JDBC easier. JDBC resource cleanup code is mundane, error prone work so these classes abstract out all of the cleanup tasks from your code leaving you with what you really wanted to do with JDBC in the first place: query and update data.

Some of the advantages of using DbUtils are:

    * No possibility for resource leaks(防止资源泄漏). Correct JDBC coding isn't difficult but it is time-consuming and tedious. This often leads to connection leaks that may be difficult to track down.
    * Cleaner, clearer persistence code (让持久层代码更加清晰). The amount of code needed to persist data in a database is drastically reduced. The remaining code clearly expresses your intention without being cluttered with resource cleanup.
    * Automatically populate JavaBean properties from ResultSets.(可以从结果集ResultSets中自动填充为JavaBean,有点ORM的味道。) You don't need to manually copy column values into bean instances by calling setter methods. Each row of the ResultSet can be represented by one fully populated bean instance.

Scope of the Package (这个DbUtils开发包所包括的内容  scope就是定界“有所为,有所不为”)

DbUtils is designed to be:

    * Small - you should be able to understand the whole package in a short amount of time. (你只要花上一点点的时间就能够明白这个工具包)
    * Transparent - DbUtils doesn't do any magic behind the scenes. You give it a query, it executes it and cleans up for you.
    //透明的,也就是设计得很简明,一般水平的人都能看懂。而且,使用起来非常方便,很人性化。
    * Fast - You don't need to create a million temporary objects to work with DbUtils.

DbUtils is not:

    * An Object/Relational bridge (O/R Mapping工具) - there are plenty of good O/R tools already. DbUtils is for developers looking to use JDBC without all the mundane pieces.  (比较土的代码是“mundane pieces”)
    * A Data Access Object (DAO) framework - DbUtils can be used to build a DAO framework though. (尽管DbUtils可以用来构建一个DAO工具,但是目前还不是。)
    * An object oriented abstraction of general database objects like a Table, Column, or PrimaryKey.(没有类似于ADO.net的DataSet那么强悍)
    * A heavyweight framework of any kind - the goal here is to be a straightforward and easy to use JDBC helper library.

Example Usage

Please see Examples Page .
Dependencies

DbUtils is intentionally a single jar distribution and relies only on a standard Java 1.3 or later JRE.  (仅仅依赖于java1.3的标准库)

你可能感兴趣的:(apache,DAO,bean,jdbc,orm)