Dbutils 详解


Common Dbutils是操作数据库的组件,对传统操作数据库的类进行二次封装,可以把结果集转化成List
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifDBUtils
包括3个包:
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils.handlers
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils.wrappers
http://www.blogjava.net/Images/OutliningIndicators/None.gifDBUtils
封装了对JDBC的操作,简化了JDBC操作,可以少写代码。
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils
http://www.blogjava.net/Images/OutliningIndicators/None.gifDbUtils
关闭链接等操作
http://www.blogjava.net/Images/OutliningIndicators/None.gifQueryRunner
进行查询的操作
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils.handlers
http://www.blogjava.net/Images/OutliningIndicators/None.gifArrayHandler
:将ResultSet中第一行的数据转化成对象数组
http://www.blogjava.net/Images/OutliningIndicators/None.gifArrayListHandler
ResultSet中所有的数据转化成ListList中存放的是 Object[]
http://www.blogjava.net/Images/OutliningIndicators/None.gifBeanHandler
:将ResultSet中第一行的数据转化成类对象
http://www.blogjava.net/Images/OutliningIndicators/None.gifBeanListHandler
:将ResultSet中所有的数据转化成ListList中存放的是类对象
http://www.blogjava.net/Images/OutliningIndicators/None.gifColumnListHandler
:将ResultSet中某一列的数据存成ListList中存放的是 Object对象
http://www.blogjava.net/Images/OutliningIndicators/None.gifKeyedHandler
:将ResultSet中存成映射,key为某一列对应为MapMap中存放的是数据
http://www.blogjava.net/Images/OutliningIndicators/None.gifMapHandler
:将ResultSet中第一行的数据存成Map映射
http://www.blogjava.net/Images/OutliningIndicators/None.gifMapListHandler
:将ResultSet中所有的数据存成ListList中存放的是Map
http://www.blogjava.net/Images/OutliningIndicators/None.gifScalarHandler
:将ResultSet中一条记录的其中某一列的数据存成Object
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.giforg.apache.commons.dbutils.wrappers
http://www.blogjava.net/Images/OutliningIndicators/None.gifSqlNullCheckedResultSet
:对ResultSet进行操作,改版里面的值
http://www.blogjava.net/Images/OutliningIndicators/None.gifStringTrimmedResultSet
:去除ResultSet中中字段的左右空格。Trim()
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
主要方法:
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifDbUtils
类:启动类
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifResultSetHandler
接口:转换类型接口
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifMapListHandler
类:实现类,把记录转化成List
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifBeanListHandler
类:实现类,把记录转化成List,使记录为JavaBean类型的对象
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifQrery Runner
类:执行SQL语句的类
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
建立三个Java文件
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
命名为BeanListExample.java
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifGuestbook.java
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifMapListExample.java
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
源码:
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifBeanListExample.java
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifCode
http://www.blogjava.net/Images/OutliningIndicators/None.gif
package  com.sy;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.DbUtils;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.QueryRunner;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.handlers.BeanListHandler;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.Connection;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.DriverManager;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.SQLException;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.util.List;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gifpublicclass  BeanListExample http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicstaticvoid  main(String[] args) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        Connection conn =   null ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String url =   " jdbc:mysql://localhost:3306/people" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String jdbcDriver =   " com.mysql.jdbc.Driver" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String user =   " root " ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String password =   " hicc " ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        DbUtils.loadDriver(jdbcDriver);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giftryhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            conn =  DriverManager.getConnection(url, user, password);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            QueryRunner qr =   new  QueryRunner();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            List results =  (List) qr.query(conn, " select id,name from guestbook" , new  BeanListHandler(Guestbook.class ));
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giffor  ( int  i  =   0 ; i  <  results.size(); i++ )  http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif                Guestbook gb =  (Guestbook) results.get(i);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif                System.out.println(" id: "   +  gb.getId() +   " ,name: "   +  gb.getName());
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif        }  catch  (SQLException e)  http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif        }  finallyhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            DbUtils.closeQuietly(conn);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifGuestbook.java
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifCode
http://www.blogjava.net/Images/OutliningIndicators/None.gifpackage  com.sy;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gifpublicclass  Guestbook http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifprivate  Integer id;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifprivate  String name;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublic  Integer getId() http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifreturn  id;
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicvoid  setId(Integer id) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifthis .id =  id;
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublic  String getName() http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifreturn  name;
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicvoid  setName(String name) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifthis .name =  name;
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifMapListExample.java
http://www.blogjava.net/Images/OutliningIndicators/None.gifhttp://www.blogjava.net/Images/OutliningIndicators/None.gifCode
http://www.blogjava.net/Images/OutliningIndicators/None.gifpackage  com.sy;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.DbUtils;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.QueryRunner;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.handlers.MapListHandler;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.Connection;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.DriverManager;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.SQLException;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.util.List;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.util.Map;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gifpublicclass  MapListExample http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicstaticvoid  main(String[] args) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        Connection conn =   null ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String url =   " jdbc:mysql://localhost:3306/people" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String jdbcDriver =   " com.mysql.jdbc.Driver" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String user =   " root " ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        String password =   " hicc " ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif        DbUtils.loadDriver(jdbcDriver);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giftryhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            conn =  DriverManager.getConnection(url, user, password);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            QueryRunner qr =   new  QueryRunner();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            List results =  (List) qr.query(conn, " select id,name from guestmessage" , new  MapListHandler());
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giffor  ( int  i  =   0 ; i  <  results.size(); i++ )  http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif                Map map =  (Map) results.get(i);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif                System.out.println(" id: "   +  map.get( " id " )  +   " ,name: "   +  map.get( " name " ));
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif        }  catch  (SQLException e)  http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif        }  finallyhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif            DbUtils.closeQuietly(conn);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
使用组建好需要添加commons - dbutils - 1.1 .jarmysql - connector - java - 5.1 . 6 - bin.jar 两个jar包。
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
配置完毕!!!
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/None.gif
//另一种方法
http://www.blogjava.net/Images/OutliningIndicators/None.gif//
使用dbutils1.0版本
http://www.blogjava.net/Images/OutliningIndicators/None.gif

http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.util. * ;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.util.logging.* ;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  java.sql.* ;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.* ;
http://www.blogjava.net/Images/OutliningIndicators/None.gifimport  org.apache.commons.dbutils.handlers.* ;
http://www.blogjava.net/Images/OutliningIndicators/None.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedBlock.gifpublicclass  TestDBUnits http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicstaticvoid  main(String[]args) throws  Exception http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  TestDBUnits test =   new  TestDBUnits();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giffor ( int  i  =   0  ; i <   1  ; i ++ )  http://www.blogjava.net/Images/dot.gif{  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   test.testQuery1();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   test.testQuery2();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   test.testUpdate();
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif  }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicvoid  testQuery1()http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giftryhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   QueryRunner qr =   new  QueryRunner() ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ResultSetHandler rsh =   new  ArrayListHandler();  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   String strsql =   " select * from test1" ;  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ArrayList result =  (ArrayList)qr.query(getConnection() ,strsql ,rsh);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif//System.out.print("");
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif
 }  catch (Exception ex) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ex.printStackTrace(System.out);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif  }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicvoid  testQuery2()http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giftryhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   QueryRunner qr =   new  QueryRunner() ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ResultSetHandler rsh =   new  MapListHandler();  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   String strsql =   " select * from test1" ;  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ArrayList result =  (ArrayList)qr.query(getConnection() ,strsql ,rsh);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giffor ( int  i  =   0  ; i <  result.size() ; i++ )  http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif    Map map =  (Map)result.get(i);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif//System.out.println(map);    
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif
  }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif//System.out.print("");
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif
 }  catch (Exception ex) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ex.printStackTrace(System.out);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif  }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gifpublicvoid  testUpdate()http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.giftryhttp://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   QueryRunner qr =   new  QueryRunner() ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ResultSetHandler rsh =   new  ArrayListHandler();
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   String strsql =   " insert test1(page ,writable ,content)values('ttt','ttt','faskldfjklasdjklfjasdklj')" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   qr.update(getConnection() ,strsql);
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif//System.out.print("");
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif
 }  catch (Exception ex) http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif   ex.printStackTrace(System.out);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif  }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifprivate   Connection getConnection() throws  InstantiationException,
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockStart.gifhttp://www.blogjava.net/Images/OutliningIndicators/ContractedSubBlock.gif   IllegalAccessException, ClassNotFoundException, SQLException http://www.blogjava.net/Images/dot.gif{
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  String strDriver =   " org.gjt.mm.mysql.Driver" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  String strUrl =   " jdbc:mysql://localhost:3306/test" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  String strUser =   " root " ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  String strPass =   "" ;
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gif  Class.forName(strDriver).newInstance();  
http://www.blogjava.net/Images/OutliningIndicators/InBlock.gifreturn  DriverManager.getConnection(strUrl, strUser, strPass);
http://www.blogjava.net/Images/OutliningIndicators/ExpandedSubBlockEnd.gif }
http://www.blogjava.net/Images/OutliningIndicators/ExpandedBlockEnd.gif}
http://www.blogjava.net/Images/OutliningIndicators/None.gif



你可能感兴趣的:(DbUtils)