use of org.apache.commons.dbutils.handlers.BeanHandler in project notes by KevinBlandy.
the class UtilsDemo method find.
public static void find() throws SQLException {
// ����QueryRunner�������ӳض���
QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
// ����SQLģ��
String sql = "select * from users where userName=?";
// ��������
Object[] params = { "Kevin" };
// ����SQLģ��Ͳ���,ִ�в�ѯ��䷵�ض���/�����ϸ��ݵڶ�����������
User user = qr.query(sql, new BeanHandler(User.class), params);
}
use of org.apache.commons.dbutils.handlers.BeanHandler in project metacat by Netflix.
the class MySqlLookupService method get.
/**
* Returns the lookup for the given <code>name</code>.
*
* @param name lookup name
* @return lookup
*/
@Override
public Lookup get(final String name) {
Lookup result;
final Connection connection = DBUtil.getReadConnection(getDataSource());
try {
final ResultSetHandler<Lookup> handler = new BeanHandler<>(Lookup.class);
result = new QueryRunner().query(connection, SQL_GET_LOOKUP, handler, name);
if (result != null) {
result.setValues(getValues(result.getId()));
}
} catch (Exception e) {
final String message = String.format("Failed to get the lookup for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
} finally {
DBUtil.closeReadConnection(connection);
}
return result;
}
use of org.apache.commons.dbutils.handlers.BeanHandler in project metacat by Netflix.
the class MySqlTagService method get.
/**
* Returns the TagItem for the given <code>name</code>.
*
* @param name tag name
* @return TagItem
*/
public TagItem get(final String name) {
TagItem result = null;
final Connection connection = DBUtil.getReadConnection(getDataSource());
try {
final ResultSetHandler<TagItem> handler = new BeanHandler<>(TagItem.class);
result = new QueryRunner().query(connection, SQL_GET_TAG_ITEM, handler, name);
if (result != null) {
result.setValues(getValues(result.getId()));
}
} catch (Exception e) {
final String message = String.format("Failed to get the tag item for name %s", name);
log.error(message, e);
throw new UserMetadataServiceException(message, e);
} finally {
DBUtil.closeReadConnection(connection);
}
return result;
}
Aggregations