本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}