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.groupon.odo.proxylib.SQLService.java
/** * @param getColumn , the data that will be returned comes from this column * @param fromColumn , we search on this column * @param fromData , searching for this specified data * @param tableName , using this table// w w w . j a v a 2s . c om * @return the Object of the getColumn we return Used for methods such as * 'getPathnameFromId' or 'getUUIDfromId' */ public Object getFromTable(String getColumn, String fromColumn, Object fromData, String tableName) { Statement query = null; ResultSet results = null; try (Connection sqlConnection = getConnection()) { query = sqlConnection.createStatement(); results = query .executeQuery("SELECT * FROM " + tableName + " WHERE " + fromColumn + "='" + fromData + "';"); if (results.next()) { Object toReturn = results.getObject(getColumn); query.close(); return toReturn; } query.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (results != null) { results.close(); } } catch (Exception e) { } try { if (query != null) { query.close(); } } catch (Exception e) { } } PathOverrideService.logger.info("error, get info from {}, to {}", fromColumn, getColumn); return null; }
From source file:com.jaspersoft.jasperserver.war.CSVServlet.java
private void printCSV(ResultSet rs, PrintWriter out) throws Exception { ResultSetMetaData md = rs.getMetaData(); int numCols = md.getColumnCount(); // print column headers for (int i = 1; i < numCols; i++) { out.write(quoteString(md.getColumnName(i))); out.write(SEP);// w w w . ja v a2 s . c o m } out.write(quoteString(md.getColumnName(numCols))); out.write(NEWLINE); // print row data while (rs.next()) { for (int i = 1; i < numCols; i++) { out.write(quoteString("" + rs.getObject(i))); out.write(SEP); } out.write(quoteString("" + rs.getObject(numCols))); out.write(NEWLINE); } }
From source file:com.egt.core.control.Controlador.java
/** * Getter para propiedad referenciaAutorizada. * * @param recurso Identificacion del recurso. * @param funcion Identificacion de la funcion. * @param strings Vector de nombres: [0] Tabla, [1] Columna Identificacion, [2] Columna Propietario, [3] * Columna Segmento./*from w w w .j a va 2 s . c o m*/ * @return true, si el usuario ejecutante esta autorizado para ejecutar la funcion sobre el recurso o si * el recurso es nulo. */ public boolean esReferenciaAutorizada(Object recurso, long funcion, String[] strings) { if (recurso == null || this.esSuperUsuario()) { return true; } String comando = this.getComandoSelectReferencia(recurso, funcion, strings); Bitacora.trace("comando" + "=" + comando); if (comando == null) { return false; } boolean es = false; String sql1 = comando; Object resultado1; ResultSet resultSet1 = null; Object objeto1; if (TLC.getAgenteSql().connected()) { try { resultado1 = TLC.getAgenteSql().executeQuery(sql1); if (resultado1 != null && resultado1 instanceof ResultSet) { resultSet1 = (ResultSet) resultado1; if (resultSet1.next()) { objeto1 = resultSet1.getObject(1); if (objeto1 != null) { es = true; } else { /* TODO: error handling */ } } else { /* TODO: error handling */ } } else { /* TODO: error handling */ } } catch (SQLException e) { TLC.getBitacora().fatal(e); } finally { DB.close(resultSet1); } } else { /* TODO: error handling */ } return es; }
From source file:com.egt.core.db.util.AgenteSql.java
public boolean isStoredProcedure(String sql) throws SQLException { Bitacora.trace(getClass(), "isStoredProcedure", sql); Object resultado;/* www .jav a 2 s . c o m*/ ResultSet resultSet; Object object; boolean is = false; if (sql != null) { String procedureName = BundleProcedimientos.getProcedureName(sql); Object[] args = new Object[] { procedureName }; resultado = executeProcedure(CHECK_PROCEDURE, args); if (resultado instanceof ResultSet) { resultSet = (ResultSet) resultado; if (resultSet.next()) { object = resultSet.getObject(1); is = BitUtils.valueOf(object); } } else if (resultado instanceof Number) { is = BitUtils.valueOf(resultado); } Bitacora.trace(procedureName + " " + is); } return is; }
From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java
private String showColumn(int index, ResultSet result) throws SQLException { StringBuilder sb = new StringBuilder(); sb.append("[").append(index).append("]"); sb.append(result.getObject(index)); return sb.toString(); }
From source file:eionet.meta.service.VocabularyInverseTest.java
@Test public void testGetInverseElem() throws Exception { Properties properties = new Properties(); properties.setProperty("http://www.dbunit.org/properties/datatypeFactory", "org.dbunit.ext.mysql.MySqlDataTypeFactory"); Connection conn = DriverManager.getConnection(Props.getProperty(PropsIF.DBURL), Props.getProperty(PropsIF.DBUSR), Props.getProperty(PropsIF.DBPSW)); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT GetInverseElemId(1) as X FROM dual"); rs.next();//from w w w. j a v a2 s . c o m int reverseId = rs.getInt("X"); Assert.assertTrue("Should have inverse elem 2", 2 == reverseId); rs = st.executeQuery("SELECT GetInverseElemId(3) as X FROM dual"); rs.next(); Assert.assertTrue("ID 3 should have no inverse element", rs.getObject("X") == null); rs = st.executeQuery("SELECT GetInverseElemId(5) as X FROM dual"); rs.next(); reverseId = rs.getInt("X"); Assert.assertTrue("ID 5 should have inverse element id=4", 4 == reverseId); rs.close(); conn.close(); }
From source file:com.manydesigns.portofino.actions.admin.appwizard.ApplicationWizard.java
public static Long safeGetLong(ResultSet rs, int index) throws SQLException { Object object = rs.getObject(index); if (object instanceof Number) { return ((Number) object).longValue(); } else {/*from w w w .j ava 2s . c o m*/ return null; } }
From source file:com.piusvelte.hydra.MSSQLConnection.java
private JSONArray getResult(ResultSet rs) throws SQLException { JSONArray rows = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); String[] columnsArr = new String[rsmd.getColumnCount()]; for (int c = 0, l = columnsArr.length; c < l; c++) columnsArr[c] = rsmd.getColumnName(c); while (rs.next()) { JSONArray rowData = new JSONArray(); for (String column : columnsArr) rowData.add((String) rs.getObject(column)); rows.add(rowData);/*ww w . jav a 2s .co m*/ } return rows; }
From source file:com.modelmetrics.cloudconverter.forceutil.DataInsertExecutor.java
public void executeWithResultSet(MigrationContext migrationContext) throws Exception { log.debug("starting data transfer (insert)..."); dao.setSalesforceSession(migrationContext.getSalesforceSession()); Collection<Sproxy> toInsert = new ArrayList<Sproxy>(); ResultSet rs = migrationContext.getResultSet(); // ResultSetMetaData rsmd = migrationContext.getResultSetMetaData(); while (rs.next()) { Sproxy current = sproxyBuilder.buildEmpty(migrationContext.getCustomObject().getFullName()); for (Iterator<MetadataProxy> iterator = migrationContext.getMetadataProxies().iterator(); iterator .hasNext();) {//from www . ja va 2s . com MetadataProxy metadataProxy = iterator.next(); current.setValue(migrationContext.getFieldMap().get(metadataProxy.getName()), rs.getObject(metadataProxy.getName())); } toInsert.add(current); if (toInsert.size() == MAX_SPROXY_BATCH_SIZE) { migrationContext.getMigrationStatusPublisher().publishStatus("executing data insert..."); dao.insert(toInsert); toInsert = new ArrayList<Sproxy>(); } } log.debug("starting the insert..."); migrationContext.getMigrationStatusPublisher().publishStatus("executing data insert..."); dao.insert(toInsert); log.debug("insert complete..."); migrationContext.getMigrationStatusPublisher().publishStatus("insert complete"); }
From source file:io.github.benas.jql.shell.StringResultSetExtractor.java
@Override public String extractData(ResultSet resultSet) throws SQLException, DataAccessException { RowCountCallbackHandler rowCountCallbackHandler = new RowCountCallbackHandler(); rowCountCallbackHandler.processRow(resultSet); int columnCount = resultSet.getMetaData().getColumnCount(); List<String> columnNames = asList(rowCountCallbackHandler.getColumnNames()); String header = getHeader(columnNames); StringBuilder result = new StringBuilder(header); result.append("\n"); while (resultSet.next()) { StringBuilder stringBuilder = new StringBuilder(); int i = 1; while (i <= columnCount) { stringBuilder.append(resultSet.getObject(i)); if (i < columnCount) { stringBuilder.append(" | "); }//from w w w. ja v a 2s . c o m i++; } result.append(stringBuilder.toString()).append("\n"); } return result.toString(); }