Apache组件commons的DbUtils的用法实例
来源:互联网 发布:mac os 磁盘分区 编辑:程序博客网 时间:2024/04/27 22:02
1 代码要连接数据库是可以跑通的,可是本人真心表示这个封装的太垃圾,远不及自己写的顺手,不建议再学一套db连接的方法,这个感觉写的还有点复杂,不好用,不推荐
package com.commons.dbutils;import java.util.*;import java.util.logging.*;import java.sql.*;import org.apache.commons.dbutils.*;import org.apache.commons.dbutils.handlers.*;public class DbUtilsTest {public static void main(String[] args) throws Exception {DbUtilsTest test = new DbUtilsTest();for (int i = 0; i < 1; i++) {test.testQuery1();test.testQuery2();test.testUpdate();}}public void testQuery1() {try {QueryRunner qr = new QueryRunner();ResultSetHandler rsh = new ArrayListHandler();String strsql = "select * from test1";ArrayList result = (ArrayList) qr.query(getConnection(), strsql,rsh);// System.out.print("");} catch (Exception ex) {ex.printStackTrace(System.out);}}public void testQuery2() {try {QueryRunner qr = new QueryRunner();ResultSetHandler rsh = new MapListHandler();String strsql = "select * from test1";ArrayList result = (ArrayList) qr.query(getConnection(), strsql,rsh);for (int i = 0; i < result.size(); i++) {Map map = (Map) result.get(i);// System.out.println(map);}// System.out.print("");} catch (Exception ex) {ex.printStackTrace(System.out);}}public void testUpdate() {try {QueryRunner qr = new QueryRunner();ResultSetHandler rsh = new ArrayListHandler();String strsql = "insert test1(page ,writable ,content)values('ttt','ttt','faskldfjklasdjklfjasdklj')";qr.update(getConnection(), strsql);// System.out.print("");} catch (Exception ex) {ex.printStackTrace(System.out);}}private Connection getConnection() throws InstantiationException,IllegalAccessException, ClassNotFoundException, SQLException {String strDriver = "com.mysql.jdbc.Driver";String strUrl = "jdbc:mysql://localhost:3306/test";String strUser = "root";String strPass = "root";Class.forName(strDriver).newInstance();return DriverManager.getConnection(strUrl, strUser, strPass);}}
- Apache组件commons的DbUtils的用法实例
- Apache的commons组件的dbutils包关于封装数据库处理的实例【这个稍微有用】
- Apache组件commons的HttpClient的用法实例
- Apache组件commons的Configuration包的用法实例
- Apache的DbUtils组件学习
- Apache组件commons的Codec包的使用实例
- Apache组件commons的MultiHashMap的一对多集合用法
- Apache组件commons之logging的常用方法实例
- Apache组件commons的IO包常用方法实例
- Apache之commons组件Lang包的常用方法实例
- Apache commons组件的使用
- commons-dbutils的操作方法
- org.apache.commons.lang.StringUtils的用法实例
- apache commons 之 DbUtils的具体使用以及源代码
- 关于apache的commons-dbutils如何读取blob类型
- 高性能的JDBC模板工具-Apache Commons DbUtils 1.6
- 关于Apache Commons DbUtils工具类的使用记录
- org.apache.commons.dbutils 的API学习(1)
- POJ 3694 Network(双连通分量缩点 + 路径压缩)
- 颇有微词 小模式 大蓝海 by 曹继忠 - 2013中国SEO排行榜
- C# 弹出窗体位置设定
- Cornerstone Svn简单使用指南
- 常用的数据标准化方法
- Apache组件commons的DbUtils的用法实例
- 单词查找树
- UML解惑---UML类图符号 各种关系说明以及举例
- Unix系统安全——绿盟科技
- 两个C++编译错误及解决办法--does not name a type和field `XX' has incomplete type
- 【js学习笔记-014】-- 转义字符
- HDU2199
- JSP中的全局变量和局部变量
- HDU2899