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:com.hangum.tadpole.engine.sql.util.resultset.ResultSetUtils.java
/** * ResultSet to List//ww w . j a v a 2s . c o m * * * * @param isShowRowNum ? ?. * @param rs ResultSet * @param limitCount * @param intLastIndex * @return * @throws SQLException */ public static TadpoleResultSet getResultToList(boolean isShowRowNum, final ResultSet rs, final int limitCount, int intLastIndex) throws SQLException { TadpoleResultSet returnRS = new TadpoleResultSet(); Map<Integer, Object> tmpRow = null; // ?? ? . int rowCnt = intLastIndex; while (rs.next()) { tmpRow = new HashMap<Integer, Object>(); int intStartIndex = 0; if (isShowRowNum) { intStartIndex++; tmpRow.put(0, rowCnt + 1); } for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { final int intColIndex = i + 1; final int intShowColIndex = i + intStartIndex; Object obj = null; try { obj = rs.getObject(intColIndex); // int type = rs.getMetaData().getColumnType(intColIndex); // if(obj instanceof oracle.sql.STRUCT) { // tmpRow.put(intShowColIndex, rs.getObject(intColIndex)); // } else if (obj == null) { tmpRow.put(intShowColIndex, PublicTadpoleDefine.DEFINE_NULL_VALUE); } else { String type = obj.getClass().getSimpleName(); if (type.toUpperCase().contains("LOB")) { tmpRow.put(intShowColIndex, rs.getObject(intColIndex)); } else { tmpRow.put(intShowColIndex, rs.getString(intColIndex)); } // if(logger.isDebugEnabled()) { // logger.debug("======[jdbc type ]===> " + rs.getMetaData().getColumnType(intColIndex) + ", class type is " + obj.getClass().getName()); // } } } catch (Exception e) { logger.error("ResutSet fetch error", e); //$NON-NLS-1$ tmpRow.put(i + intStartIndex, ""); //$NON-NLS-1$ } } returnRS.getData().add(tmpRow); // ? ? . (hive driver getRow ? ) --;; 2013.08.19, hangum if (limitCount == (rowCnt + 1)) { returnRS.setEndOfRead(false); break; } rowCnt++; } return returnRS; }
From source file:com.netspective.axiom.sql.ResultSetUtils.java
public Object getResultSetSingleColumn(ResultSet rs) throws SQLException { if (rs.next()) return rs.getObject(1); else//from www. java2 s. co m return null; }
From source file:net.orpiske.ssps.common.db.SimpleRsHandler.java
@Override public T handle(ResultSet rs) throws SQLException { // No records to handle :O if (!rs.next()) { return null; }/*ww w .j a va 2 s. c o m*/ ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); PropertyUtils.setSimpleProperty(dto, javaProperty, value); } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:com.qualogy.qafe.business.integration.rdb.MetaDataRowMapper.java
/** * Method for mapping rows inherited from RowMapper. * Method maps rows to a Map using columnname. *//* w w w. j a v a 2 s. co m*/ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { // Map<String, Object> output = new CaseInsensitiveMap(); Map<String, Object> output = new DataMap(); ResultSetMetaData md = rs.getMetaData(); for (int i = 1; i <= md.getColumnCount(); i++) { output.put(md.getColumnName(i), rs.getObject(i)); } return output; }
From source file:dk.nsi.haiba.epimibaimporter.dao.impl.ClassificationCheckDAOImpl.java
protected Object[] getValues(ResultSet rs, String[] columnsToCopy) { Object[] returnValue = new Object[columnsToCopy.length]; for (int i = 0; i < returnValue.length; i++) { try {/* ww w . j av a 2s . com*/ returnValue[i] = rs.getObject(columnsToCopy[i]); } catch (SQLException e) { log.error("unable to extract value for column " + columnsToCopy[i], e); } } return returnValue; }
From source file:com.orientechnologies.orient.jdbc.spring.CorenetThread.java
public void run() { try {/* w w w . ja v a2s . com*/ PreparedStatement queryPrepStatement = connection .prepareStatement("SELECT FROM OGraphVertex WHERE name = ?"); queryPrepStatement.setString(1, ROOT_VERTEX_NAME); ResultSet rs = queryPrepStatement.executeQuery(); Assert.assertTrue(NAME + "There is no vertex with name " + ROOT_VERTEX_NAME, rs.first()); //the RID is always the first element in the RS Object vertexId = rs.getObject(1); OrientGraph g = connection.unwrap(OrientGraph.class); Vertex v = g.getVertex(vertexId); Assert.assertNotNull(NAME + "There is no vertex for rid ", v); Iterator<Edge> containmentRels = v.getEdges(Direction.OUT, SUPPLY_RELATION_EDGE).iterator(); Assert.assertTrue( NAME + "There is no edge with label '" + SUPPLY_RELATION_EDGE + "' coming from " + v.toString(), containmentRels.hasNext()); String prefix = NAME + "Values:: "; StringBuilder textToBePrinted = new StringBuilder(prefix); Edge currentRel; while (containmentRels.hasNext()) { currentRel = containmentRels.next(); if (textToBePrinted.length() == prefix.length()) textToBePrinted.append(currentRel.getVertex(Direction.IN).getProperty("name").toString()); else textToBePrinted .append(", " + currentRel.getVertex(Direction.IN).getProperty("name").toString()); } System.out.println(textToBePrinted); } catch (SQLException e) { e.printStackTrace(); Assert.fail(); } }
From source file:fr.gael.dhus.database.liquibase.ExtractProductDatesAndDownloadSize.java
@Override public void execute(Database database) throws CustomChangeException { // contentStart contentEnd ingestionDate download.size JdbcConnection databaseConnection = (JdbcConnection) database.getConnection(); try {//from w w w . jav a 2s. co m // SELECT PRODUCT_ID, QUERYABLE, VALUE FROM METADA_INDEXES PreparedStatement getQueryables = databaseConnection .prepareStatement("SELECT PRODUCT_ID, QUERYABLE, VALUE " + "FROM METADATA_INDEXES"); ResultSet res = getQueryables.executeQuery(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); while (res.next()) { Long productIdentifier = (Long) res.getObject("PRODUCT_ID"); String queryable = (String) res.getObject("QUERYABLE"); String value = (String) res.getObject("VALUE"); String query = ""; if ("beginPosition".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET CONTENTSTART = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else if ("endPosition".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET CONTENTEND = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else if ("ingestionDate".equals(queryable)) { Date d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(value); query = "UPDATE PRODUCTS SET INGESTIONDATE = '" + sdf.format(d) + "' WHERE ID = " + productIdentifier; } else { continue; } PreparedStatement updateProduct = databaseConnection.prepareStatement(query); updateProduct.execute(); updateProduct.close(); } getQueryables.close(); } catch (Exception e) { LOGGER.error("Error during liquibase update " + "'ExtractProductDatesAndDownloadSize'", e); } try { PreparedStatement getQueryables = databaseConnection .prepareStatement("SELECT p.ID, p.DOWNLOAD_PATH FROM PRODUCTS p "); ResultSet res = getQueryables.executeQuery(); while (res.next()) { Long productIdentifier = (Long) res.getObject("ID"); String path = (String) res.getObject("DOWNLOAD_PATH"); File dl = new File(path); if (dl.exists()) { PreparedStatement updateProduct = databaseConnection .prepareStatement("UPDATE PRODUCTS SET DOWNLOAD_SIZE = " + dl.length() + " WHERE ID = " + productIdentifier); updateProduct.execute(); updateProduct.close(); } } getQueryables.close(); } catch (Exception e) { LOGGER.error("Error during liquibase update " + "'ExtractProductDatesAndDownloadSize'", e); } }
From source file:net.orpiske.ssps.common.registry.SoftwareInventoryRsHandler.java
@Override public SoftwareInventoryDto handle(ResultSet rs) throws SQLException { // No records to handle :O if (!rs.next()) { return null; }// w ww. ja v a2 s.c o m ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.orpiske.ssps.common.repository.search.cache.PackageCacheRsHandler.java
@Override public PackageInfo handle(ResultSet rs) throws SQLException { // No records to handle :O if (!rs.next()) { return null; }/*from www . j a v a 2s.c o m*/ ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { Object value = rs.getObject(i); String name = meta.getColumnName(i); try { /* * We convert the column name to a more appropriate and java like name * because some columns are usually named as some_thing whereas Java * properties are named someThing. This call does this conversion. */ String javaProperty = NameConverter.sqlToProperty(name); if (javaProperty.equals("version")) { Version version = Version.toVersion((String) value); PropertyUtils.setSimpleProperty(dto, javaProperty, version); } else { PropertyUtils.setSimpleProperty(dto, javaProperty, value); } } catch (Exception e) { throw new SQLException("Unable to set property " + name + " for bean" + dto.getClass(), e); } } return dto; }
From source file:net.mlw.vlh.adapter.jdbc.objectWrapper.DefaultWrapperAdapter.java
/** * @param result//from w ww .ja v a2 s . c om * @return * @throws SQLException */ private Object getOrignalRecord(ResultSet result) throws SQLException { if (wrapResultSet) { return result; } else { if (_columnName != null && _columnName.length() > 0) { return result.getObject(_columnName); } else { return result.getObject(_columnNumber); } } }