数据源配置

1.CommonDbUtilsDao.java


package com.jdrx.ecis.core.dao;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;


import javax.sql.DataSource;


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.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;


public class CommonDbUtilsDAO  {

DataSource dataSource;

public Object[] query(String sql,Object[] argus) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
return qr.query(sql, new ArrayHandler(),argus);
}


public List queryListArray(String sql,Object[] argus) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
    return  qr.query(sql,new ArrayListHandler() ,argus);
}


public T queryObjectList(String sql,Object[] argus,Class clazz) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
return  qr.query(sql,new BeanHandler(clazz) , argus);
}

public List queryListArray2(String sql,Object[] argus,Class clazz) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
List acclist = qr.query(sql,new BeanListHandler(clazz),argus);
return acclist;
}


public Map get(String sql,Object[] argus) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
return qr.query(sql,new MapHandler(),argus );
}

public  List> queryMapList(String sql,Object[] argus) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
return qr.query(sql,new MapListHandler(),argus );
}


public  List> queryColumnList(String sql,Object[] argus,String clumnName) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
return (List>) qr.query(sql,new ColumnListHandler(clumnName) );
}


public long count(String sql,Object[] argus) throws SQLException{
QueryRunner qr=new QueryRunner(dataSource);
        Long count = (Long)qr.query(sql,new ScalarHandler(1),argus );
        return count;
}


public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
 
}


2.spring 配置文件



xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
default-lazy-init="true">


Spring azkaban DS Configuration

   


   
    
   
   

    

 
   
   
   







 



















    





你可能感兴趣的:(数据库)