List of usage examples for java.sql ResultSet getObject
Object getObject(String columnLabel) throws SQLException;
Gets the value of the designated column in the current row of this ResultSet
object as an Object
in the Java programming language.
From source file:cc.cicadabear.security.infrastructure.jdbc.OauthClientDetailsRowMapper.java
private Integer getInteger(ResultSet rs, String columnName) throws SQLException { final Object object = rs.getObject(columnName); if (object != null) { return (Integer) object; }//from w ww.ja v a 2 s . c o m return null; }
From source file:org.mayocat.shop.payment.store.jdbi.mapper.GatewayTenantDataMapper.java
@Override public GatewayTenantData map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { UUID tenantId = (UUID) resultSet.getObject("tenant_id"); String gateway = resultSet.getString("gateway"); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); try {//from w w w. j av a 2s .co m Map<String, Object> data = mapper.readValue(resultSet.getString("tenant_data"), new TypeReference<Map<String, Object>>() { }); return new GatewayTenantData(tenantId, gateway, data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(GatewayTenantDataMapper.class); logger.error("Failed to de-serialize gateway tenant data", e); return null; } }
From source file:org.mayocat.shop.payment.store.jdbi.mapper.GatewayCustomerDataMapper.java
@Override public GatewayCustomerData map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { UUID customerId = (UUID) resultSet.getObject("customer_id"); String gateway = resultSet.getString("gateway"); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); try {/*from w w w. ja v a2s . c o m*/ Map<String, Object> data = mapper.readValue(resultSet.getString("customer_data"), new TypeReference<Map<String, Object>>() { }); return new GatewayCustomerData(customerId, gateway, data); } catch (IOException e) { final Logger logger = LoggerFactory.getLogger(GatewayCustomerDataMapper.class); logger.error("Failed to de-serialize gateway customer data", e); return null; } }
From source file:eionet.cr.util.sql.SingleObjectReader.java
@Override @SuppressWarnings("unchecked") public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException { resultList.add((T) rs.getObject(1)); }
From source file:org.mayocat.shop.billing.store.jdbi.mapper.AbstractOrderMapper.java
protected void fillOrderSummary(ResultSet resultSet, OrderSummary order) throws SQLException { order.setId((UUID) resultSet.getObject("id")); order.setSlug(resultSet.getString("slug")); order.setBillingAddressId((UUID) resultSet.getObject("billing_address_id")); order.setDeliveryAddressId((UUID) resultSet.getObject("delivery_address_id")); order.setCustomerId((UUID) resultSet.getObject("customer_id")); order.setCreationDate(resultSet.getTimestamp("creation_date")); order.setUpdateDate(resultSet.getTimestamp("update_date")); order.setNumberOfItems(resultSet.getLong("number_of_items")); order.setCurrency(Currency.getInstance(resultSet.getString("currency"))); order.setItemsTotal(resultSet.getBigDecimal("items_total")); order.setItemsTotalExcl(resultSet.getBigDecimal("items_total_excl")); order.setShipping(resultSet.getBigDecimal("shipping")); order.setShippingExcl(resultSet.getBigDecimal("shipping_excl")); order.setGrandTotal(resultSet.getBigDecimal("grand_total")); order.setGrandTotalExcl(resultSet.getBigDecimal("grand_total_excl")); order.setStatus(OrderSummary.Status.valueOf(resultSet.getString("status"))); order.setAdditionalInformation(resultSet.getString("additional_information")); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new GuavaModule()); try {/* w ww .jav a 2 s. c o m*/ Map<String, Object> data = mapper.readValue(resultSet.getString("order_data"), new TypeReference<Map<String, Object>>() { }); order.setOrderData(data); } catch (IOException e) { logger.error("Failed to deserialize order data", e); } }
From source file:org.string_db.jdbc.GenericQueryProcessor.java
/** * Query database for two columns and collect results in a map. * <p/>/*w w w . jav a2 s.c o m*/ * <em>Warning</em>: possible SQL injection * * @param firstColumn name (escaped if SQL keyword) * @param secondColumn name (escaped if SQL keyword) * @param table name * @param rowMapper items collector * @param <K> first column type * @param <V> second column type * @param <R> type for aggregated values from the second column * @return * @throws org.springframework.dao.DataAccessException if there is any problem executing the query */ public <K, V, R> Map<K, R> selectTwoColumns(String firstColumn, String secondColumn, String table, final TwoColumnRowMapper<K, V, R> rowMapper) { final String query = String.format("SELECT %s, %s FROM %s ", firstColumn, secondColumn, table); final Map<K, R> r = new HashMap<>(); jdbcTemplate.query(query, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { rowMapper.addToMap((K) resultSet.getObject(1), (V) resultSet.getObject(2), r); } }); return r; }
From source file:org.string_db.jdbc.GenericQueryProcessor.java
/** * Query database for two columns and collect results in a map. * <p/>/* w w w.j av a 2 s . c o m*/ * * <em>Warning</em>: possible SQL injection * * @param firstColumn name (escaped if SQL keyword) * @param secondColumn name (escaped if SQL keyword) * @param table name * @param rowMapper items collector * @param filter query criteria * @param parameters named params defined in <code>filter</code> * @param <K> first column type * @param <V> second column type * @param <R> type for aggregated values from the second column * @return * @throws org.springframework.dao.DataAccessException if there is any problem executing the query */ public <K, V, R> Map<K, R> selectTwoColumns(String firstColumn, String secondColumn, String table, final TwoColumnRowMapper<K, V, R> rowMapper, String filter, SqlParameterSource parameters) { final String query = String.format("SELECT %s, %s FROM %s WHERE %s", firstColumn, secondColumn, table, filter); final Map<K, R> r = new HashMap<>(); namedParameterJdbcTemplate.query(query, parameters, new RowCallbackHandler() { @Override public void processRow(ResultSet resultSet) throws SQLException { rowMapper.addToMap((K) resultSet.getObject(1), (V) resultSet.getObject(2), r); } }); return r; }
From source file:org.mayocat.cms.pages.store.jdbi.mapper.PageMapper.java
@Override public Page map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { Page page = new Page((UUID) resultSet.getObject("id")); if (resultSet.getObject("published") != null) { page.setPublished(resultSet.getBoolean("published")); }/* w ww . j a v a 2s . co m*/ page.setTitle(resultSet.getString("title")); page.setSlug(resultSet.getString("slug")); page.setContent(resultSet.getString("content")); page.setFeaturedImageId((UUID) resultSet.getObject("featured_image_id")); if (!Strings.isNullOrEmpty(resultSet.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try { Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(resultSet.getString("localization_data"), Map[].class); for (Map map : data) { try { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } catch (IllegalArgumentException e) { // Invalid locale, just ignore it } } page.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } String model = resultSet.getString("model"); if (!Strings.isNullOrEmpty(model)) { page.setModel(model); } return page; }
From source file:org.mayocat.shop.catalog.store.jdbi.mapper.CollectionMapper.java
@Override public Collection map(int index, ResultSet result, StatementContext statementContext) throws SQLException { Collection collection = new Collection((UUID) result.getObject("id")); collection.setParentId((UUID) result.getObject("parent_id")); collection.setSlug(result.getString("slug")); collection.setTitle(result.getString("title")); collection.setDescription(result.getString("description")); collection.setFeaturedImageId((UUID) result.getObject("featured_image_id")); if (MapperUtils.hasColumn("localization_data", result) && !Strings.isNullOrEmpty(result.getString("localization_data"))) { ObjectMapper mapper = new ObjectMapper(); try {//from ww w . j a v a 2 s .c o m Map<Locale, Map<String, Object>> localizedVersions = Maps.newHashMap(); Map[] data = mapper.readValue(result.getString("localization_data"), Map[].class); for (Map map : data) { localizedVersions.put(LocaleUtils.toLocale((String) map.get("locale")), (Map) map.get("entity")); } collection.setLocalizedVersions(localizedVersions); } catch (IOException e) { throw new SQLException("Failed to de-serialize localization JSON data", e); } } return collection; }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.excel.DBExcelUtility.java
public static void displayResultSetRow(ResultSet rs) throws Exception { int maxcol = 20; StringBuffer sb = new StringBuffer(); ResultSetMetaData mdata = rs.getMetaData(); sb.append("\n"); maxcol = mdata.getColumnCount();/*from ww w .ja va 2 s.co m*/ for (int i = 1; i <= maxcol; i++) { sb.append(mdata.getColumnName(i) + "\t"); } int rowcount = 0; sb.append("\n"); for (int i = 1; i <= maxcol; i++) { try { sb.append(rs.getObject(i) + "\t"); } catch (Exception e) { System.out.println("Exception " + e); } } System.out.println(sb.toString()); }