当前位置: 首页>>代码示例>>Java>>正文


Java BeanHandler类代码示例

本文整理汇总了Java中org.apache.commons.dbutils.handlers.BeanHandler的典型用法代码示例。如果您正苦于以下问题:Java BeanHandler类的具体用法?Java BeanHandler怎么用?Java BeanHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BeanHandler类属于org.apache.commons.dbutils.handlers包,在下文中一共展示了BeanHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: queryEntity

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
     * 查询实体
     */

    public static <T> T queryEntity(Class<T> entityClass, String sql , Object... params) {
        T entity;
        try {
            Connection connection = getConnection();
            entity = QUERY_RUNNER.query(connection,sql, new BeanHandler<T>(entityClass), params);
        }catch (SQLException e){
            LOGGER.error("query entity failure", e);
            throw  new RuntimeException(e);
        }
//        finally {
//            closeConnection();
//        }
        return  entity;
    }
 
开发者ID:MiracleWong,项目名称:Smart-Book-Code,代码行数:19,代码来源:DatabaseHelper.java

示例2: main

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
public static void main(String[] args) throws SQLException {

		final String url = "jdbc:h2:./target/test;AUTO_SERVER=TRUE";
		final String driver = "org.h2.Driver";
		final String usr = "sa";
		final String pwd = "";

		QueryRunner run = new QueryRunner();

		DbUtils.loadDriver(driver);
		Connection conn = DriverManager.getConnection(url, usr, pwd);
		// -----------------------------------------------------------------------------------
		ResultSetHandler<Employee> resultHandler = new BeanHandler<Employee>(
				Employee.class);

		try {
			Employee emp = run.query(conn,
					"SELECT * FROM employee WHERE employeename=?",
					resultHandler, "Jose");
			System.out.println(emp.getEmployeeId());
		} finally {
			DbUtils.close(conn);
		}

	}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:26,代码来源:BeanHandlerExample.java

示例3: findFrenteManzana

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
@Override
public FrenteManzana findFrenteManzana(String point, Server server)
		throws Exception {
	String sql = "select nomvial as vialidad, tipovial as tipoVialidad, nomref1 as entrevialidad1, nomref2 as entrevialidad2,"
			+ " tipovr1 as tipoEntrevialidad1, tipovr2 as tipoEntrevialidad2, nombre_loc as localidad, cve_loc as cveloc,"
			+ " nombre_mun as municipio, cve_mun as cvemun, nombre_ent as entidad, nomasen as asentamiento, cp as codigoPostal,"
			+ " ST_AsText(ST_Line_Interpolate_Point(ST_LineMerge(the_geom), ST_Line_Locate_Point(ST_LineMerge(the_geom), ST_GeomFromText(?, 900913)))) as punto,"
			+ " ST_Distance(ST_GeomFromText(?, 900913), the_geom) as distance"
			+ " from localidadesmzn.frentesdemanzana_mgn"
			+ " where ST_DWithin(ST_GeomFromText(?, 900913), the_geom, 40)"
			+ " order by distance" + " limit 1";
	Connection conn = ConnectionManager.getConnectionW(server);
	ResultSetHandler<FrenteManzana> rsh = new BeanHandler<FrenteManzana>(
			FrenteManzana.class);
	QueryRunner qr = new QueryRunner();
	FrenteManzana fm = null;
	try {
		fm = qr.query(conn, sql, rsh, point, point, point);
	} finally {
		ConnectionManager.closeConnection(conn);
	}
	return fm;
}
 
开发者ID:MxSIG,项目名称:TableAliasV60,代码行数:24,代码来源:ImssDaoImpl.java

示例4: findNumeroExterior

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
@Override
public NumeroExterior findNumeroExterior(String point, Server server)
		throws Exception {
	String sql = "select numextnum as numeroExterior, numextalf as numeroExteriorAlf, numextant as numeroAnterior,"
			+ " nomvial as vialidad, tipovial as tipoVialidad, nomref1 as entrevialidad1, nomref2 as entrevialidad2,"
			+ " tipovr1 as tipoEntrevialidad1, tipovr2 as tipoEntrevialidad2, nombre_loc as localidad, cve_loc as cveloc,"
			+ " nombre_mun as municipio, cve_mun as cvemun, nombre_ent as entidad, nomasen as asentamiento, cp as codigoPostal,"
			+ " ST_Distance(ST_GeomFromText(?, 900913), the_geom) as distance,"
			+ " ST_AsText(the_geom) as punto"
			+ " from localidadesmzn.numeroexteriorurbano"
			+ " where ST_DWithin(ST_GeomFromText(?, 900913), the_geom, 40)"
			+ " order by distance" + " limit 1";
	Connection conn = ConnectionManager.getConnectionW(server);
	ResultSetHandler<NumeroExterior> rsh = new BeanHandler<NumeroExterior>(
			NumeroExterior.class);
	QueryRunner qr = new QueryRunner();
	NumeroExterior ne = null;
	try {
		ne = qr.query(conn, sql, rsh, point, point);
	} finally {
		ConnectionManager.closeConnection(conn);
	}
	return ne;
}
 
开发者ID:MxSIG,项目名称:TableAliasV60,代码行数:25,代码来源:ImssDaoImpl.java

示例5: getTotales

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
private Integer getTotales(Connection conn) throws SQLException {
    QueryRunner qr = new QueryRunner();
    String sqlWhere = DenueWhereCreator.getWhere(areasGeo, estratos, actividades, optParams);
    dto.setFiltro(sqlWhere.replaceAll("'", "''"));
    String sql = "select count(*) as total from "+DenueTable.getEsquema()+"."+DenueTable.getTabla()+" ";
    ParamConsultaTotal total = null;
    if (sqlWhere != null && sqlWhere.length() > 0) {
        sql = sql + " where " + sqlWhere;
        ResultSetHandler rsh = new BeanHandler(ParamConsultaTotal.class);
        total = (ParamConsultaTotal) qr.query(conn, sql, rsh);
    } else {
        total = new ParamConsultaTotal();
        total.setTotal(4374600);
    }
    return total.getTotal();
}
 
开发者ID:MxSIG,项目名称:TableAliasV60,代码行数:17,代码来源:ParamConsultaWrapper.java

示例6: getFailedAttempts

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
public void getFailedAttempts(final FinishedLensQuery query) {
  if (query != null) {
    String handle = query.getHandle();
    ResultSetHandler<List<FailedAttempt>> rsh = new BeanHandler<List<FailedAttempt>>(null) {
      @Override
      public List<FailedAttempt> handle(ResultSet rs) throws SQLException {
        List<FailedAttempt> attempts = Lists.newArrayList();
        while (rs.next()) {
          FailedAttempt attempt = new FailedAttempt(rs.getString(3), rs.getDouble(4), rs.getString(5),
            rs.getString(6), rs.getLong(7), rs.getLong(8));
          attempts.add(attempt);
        }
        return attempts;
      }
    };
    String sql = "select * from failed_attempts where handle=? order by attempt_number";
    QueryRunner runner = new QueryRunner(ds);
    try {
      query.setFailedAttempts(runner.query(sql, rsh, handle));
    } catch (SQLException e) {
      log.error("SQL exception while executing query.", e);
    }
  }
}
 
开发者ID:apache,项目名称:lens,代码行数:25,代码来源:LensServerDAO.java

示例7: queryEntity

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 查询对应的实体,返回单条记录
 */
public <T> T queryEntity(Class<T> entityClass, String sql, Object... params) {
    T result;
    try {
    	result = queryRunner.query(sql, new BeanHandler<T>(entityClass), params);
    } catch (SQLException e) {
        logger.error("查询出错!");
        throw new RuntimeException(e);
    }
    printSQL(sql);
    return result;
}
 
开发者ID:smxc,项目名称:garlicts,代码行数:15,代码来源:JdbcTemplate.java

示例8: queryEntity

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 查询客户实体
 * 
 * @param entityClass
 * @param sql
 * @param params
 * @return
 */
public static <T> T queryEntity(Class<T> entityClass, String sql,
		Object... params) {
	T entity;
	try {
		Connection conn = getConnection();
		entity = QUERY_RUNNER.query(conn, sql, new BeanHandler<T>(
				entityClass), params);
	} catch (SQLException e) {
		LOGGER.error("query entity   failure", e);
		throw new RuntimeException(e);
	}
	return entity;
}
 
开发者ID:longjiazuo,项目名称:light-framework,代码行数:22,代码来源:DataBaseHelper.java

示例9: findByUsername

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 根据其真实姓名查找相应的教师职工信息
 */

@Override
public Faculty findByUsername(String fUsername) {
	try{
		Connection con = JdbcUtils.getConnection();
		String sql = "select * from tb_faculty where fUserName = ?";
		Faculty result = runner.query(con, sql, new BeanHandler<Faculty>(Faculty.class),fUsername);
		return result;
	}catch(Exception e){
		e.printStackTrace();
	}
	return null;

}
 
开发者ID:binjie09,项目名称:tttclass,代码行数:18,代码来源:FacultyDaoImpl.java

示例10: findByID

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 根据教师工id查找其对应的信息
 */
@Override
public Faculty findByID(String fID) {
	try{
		Connection con = JdbcUtils.getConnection();
		String sql = "select * from tb_faculty where fID = ?";
		Faculty result = runner.query(con, sql, new BeanHandler<Faculty>(Faculty.class),fID);
		System.out.println(result.toString());
		return result;
	}catch(Exception e){
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:binjie09,项目名称:tttclass,代码行数:17,代码来源:FacultyDaoImpl.java

示例11: findByID

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 根据id查找相应的学生记录
 */
@Override
public Student findByID(String sID) {
	try{
		Connection con = JdbcUtils.getConnection();
		String sql = "select * from tb_student where sID = ?";
		Student result = runner.query(con, sql, new BeanHandler<Student>(Student.class),sID);
		System.out.println(result.toString());
		return result;
	}catch(Exception e){
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:binjie09,项目名称:tttclass,代码行数:17,代码来源:StudentDaoImp.java

示例12: findPhotoByID

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
/**
 * 根据照片路径查找相应的学生记录
 */

@Override
public String findPhotoByID(String sID) {
	try{
		Connection con = JdbcUtils.getConnection();
		String sql = "select * from tb_student where sID = ?";
		Student student = runner.query(con, sql, new BeanHandler<Student>(Student.class),sID);
		return student.getsPhotoPath();
	}catch(Exception e){
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:binjie09,项目名称:tttclass,代码行数:17,代码来源:StudentDaoImp.java

示例13: queryEntity

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
public static <T> T queryEntity(Class<T> entityClass, String sql, Object... params) {
    T entity;
    try {
        Connection conn = getConnection();
        entity = QUERY_RUNNER.query(conn, sql, new BeanHandler<T>(entityClass), params);
    } catch (SQLException e) {
        LOGGER.error("query entity failure", e);
        throw new RuntimeException(e);
    }

    return entity;
}
 
开发者ID:diaojibo,项目名称:rock-framework,代码行数:13,代码来源:DatabaseHelper.java

示例14: queryBean

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
public static <T> T queryBean(QueryRunner runner, Class<T> cls, Map<String, String> map, String sql, Object... params) {
    T result;
    try {
        if (MapUtil.isNotEmpty(map)) {
            result = runner.query(sql, new BeanHandler<T>(cls, new BasicRowProcessor(new BeanProcessor(map))), params);
        } else {
            result = runner.query(sql, new BeanHandler<T>(cls), params);
        }
        printSQL(sql);
    } catch (SQLException e) {
        logger.error("查询出错!", e);
        throw new RuntimeException(e);
    }
    return result;
}
 
开发者ID:thinkhoon,项目名称:tkhoon,代码行数:16,代码来源:DBUtil.java

示例15: query

import org.apache.commons.dbutils.handlers.BeanHandler; //导入依赖的package包/类
@Override
public T query(String sql, Object... args) {
	Connection connection = null;

	try {
		connection = ConnectionContext.getInstance().get();
		return queryRunner.query(connection, sql, new BeanHandler<T>(clazz),args);
	} catch (Exception e) {
		e.printStackTrace();
	} 
	return null;
}
 
开发者ID:hoticer,项目名称:FoodOrder,代码行数:13,代码来源:BaseDao.java


注:本文中的org.apache.commons.dbutils.handlers.BeanHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。