[转载]Dbutil 的使用示例
DBUtils知识:
http://blog.csdn.net/farreaching665/article/details/7101132
?
package
?cn.lining.test;???
??
import
?java.sql.Connection;???
import
?java.sql.DriverManager;???
import
?java.sql.SQLException;???
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.ColumnListHandler;???
import
?org.apache.commons.dbutils.handlers.KeyedHandler;???
import
?org.apache.commons.dbutils.handlers.MapHandler;???
import
?org.apache.commons.dbutils.handlers.MapListHandler;???
import
?org.apache.commons.dbutils.handlers.ScalarHandler;???
??
public
?class
?test?{???
?@SuppressWarnings
("unchecked"
)???
?public
?static
?void
?main(String[]?args)?throws
?ClassNotFoundException?{???
??
??UserField?userField?=?new
?UserField();???
??
??Connection?conn?=?null
;???
??String?jdbcURL?=?"jdbc:mysql://localhost:3306/macaw4"
;???
??String?jdbcDriver?=?"com.mysql.jdbc.Driver"
;???
??try
?{???
???DbUtils.loadDriver(jdbcDriver);???
???conn?=?DriverManager.getConnection(jdbcURL,?"root"
,?"root"
);???
???conn.setAutoCommit(false
);