本文整理汇总了Java中org.apache.commons.dbutils.handlers.MapHandler类的典型用法代码示例。如果您正苦于以下问题:Java MapHandler类的具体用法?Java MapHandler怎么用?Java MapHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapHandler类属于org.apache.commons.dbutils.handlers包,在下文中一共展示了MapHandler类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: queryMap
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
/**
* 查询对应的数据,返回单条记录(列名 => 数据)
*/
public Map<String, Object> queryMap(String sql, Object... params) {
Map<String, Object> map;
try {
map = queryRunner.query(sql, new MapHandler(), params);
} catch (SQLException e) {
logger.error("查询出错!");
throw new RuntimeException(e);
}
printSQL(sql);
return map;
}
示例2: findRecord
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
/**
* Find one record via arbitrary SQL and return it as a hashmap
*
* @param sql
* @param args
* @return
*/
public Map<String, Object> findRecord(String sql, Object... args) {
QueryRunner runner = new QueryRunner(dataSource);
MapHandler handler = new MapHandler();
try {
return runner.query(sql, handler, args);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例3: queryMap
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
public static Map<String, Object> queryMap(QueryRunner runner, String sql, Object... params) {
Map<String, Object> result;
try {
result = runner.query(sql, new MapHandler(), params);
} catch (SQLException e) {
logger.error("查询出错!", e);
throw new RuntimeException(e);
}
printSQL(sql);
return result;
}
示例4: selectOneBySql
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
@Override
public <T> T selectOneBySql(String sql, Object[] params, Class<T> classz) {
QueryRunner queryRunner = new QueryRunner();
Connection conn = getDbConnectionFactory().getConnection();
printSQL(sql, params);
try {
if (classz.isAssignableFrom(Model.class)) {
List<T> list = (List<T>) queryRunner.query(conn, sql, new AnnotationBeanListHandler(classz), params);
if (list.size() > 0) {
return list.get(0);
}
return null;
} else if (baseType.contains(classz)) {
return queryRunner.query(conn, sql, new ScalarHandler<T>(), params);
} else {
Map map = queryRunner.query(conn, sql, new MapHandler(), params);
return (T) map;
}
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
getDbConnectionFactory().releaseConnection(conn);
}
}
示例5: findGeometryByPoint
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
@Override
public Object findGeometryByPoint(String sql, String point, Server server)
throws Exception {
Connection conn = ConnectionManager.getConnectionW(server);
MapHandler mh = new MapHandler();
QueryRunner qr = new QueryRunner();
Map<String, Object> response = new HashMap<String, Object>();
try {
response = qr.query(conn, sql, mh, point);
} finally {
ConnectionManager.closeConnection(conn);
}
return response;
}
示例6: findGeometryByCvegeo
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
@Override
public Object findGeometryByCvegeo(String sql, String cvegeo, Server server)
throws Exception {
Connection conn = ConnectionManager.getConnectionW(server);
MapHandler mh = new MapHandler();
QueryRunner qr = new QueryRunner();
Map<String, Object> response = new HashMap<String, Object>();
try {
response = qr.query(conn, sql, mh, cvegeo);
} finally {
ConnectionManager.closeConnection(conn);
}
return response;
}
示例7: query
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
public static Map query(String sql, Object... params) {
try {
QueryRunner qRunner = new QueryRunner(MySQLConnTools.getMySQLDataSource());
Map obj = qRunner.query(sql, new MapHandler(), params);
return obj;
} catch (SQLException e) {
// logger.error(e.getMessage());
e.printStackTrace();
}
return null;
}
示例8: findMap
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
/**
* //TODO 根据sql查询一个map
*
* @param sql
* @param params
* @return
*/
public static Map<String, Object> findMap(String sql, Object... params) {
Map<String, Object> map;
try {
map = getQueryRunner().query(sql, new MapHandler(), params);
} catch (SQLException e) {
logger.error("queryMap.查询map出错:" + sql, e);
throw new QueryException(e);
}
logger.debug("sql:" + sql + "\n params:" + Arrays.toString(params));
return map;
}
示例9: queryForMap
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
public MutableMap<String, Object> queryForMap(Connection conn, String sql) {
return MapAdapter.adapt(this.query(conn, sql, new MapHandler()));
}
示例10: getFood
import org.apache.commons.dbutils.handlers.MapHandler; //导入依赖的package包/类
/**
* 从Mysql得到Food
*
* @param foodId id
* @return map
* @throws SQLException
*/
@Deprecated
public Map<String, Object> getFood(int foodId) throws SQLException {
return queryRunner.query("select * from food where id = ? LIMIT 1", new MapHandler(), foodId);
}