List of usage examples for org.springframework.jdbc.support.rowset SqlRowSetMetaData getColumnNames
String[] getColumnNames() throws InvalidResultSetAccessException;
From source file:com.esa.infocontrol.data.jdbc.BaseDataJDBC.java
public static DataArrayWrapper getList(DataSource dataSource, String query, MapSqlParameterSource params) { LOG.debug("QUERY: {}", query); if (params != null) { LOG.debug("\tPARAMETERS: {}", params.getValues().toString()); }/*from w w w . jav a 2 s. c o m*/ NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); SqlRowSet rs = jdbcTemplate.queryForRowSet(query, params); SqlRowSetMetaData md = rs.getMetaData(); LOG.debug("\tCOLUMNS: {}", Arrays.toString(md.getColumnNames())); List<DataRow> dataList = new ArrayList<>(); ColumnMetaData[] columnMetaData = new ColumnMetaData[md.getColumnCount()]; for (int i = 1; i <= md.getColumnCount(); ++i) { columnMetaData[i - 1] = new ColumnMetaData(md.getColumnLabel(i), md.getColumnType(i)); } while (rs.next()) { DataRow row = new DataRow(md.getColumnCount()); for (int i = 1; i <= md.getColumnCount(); ++i) { row.add(rs.getString(i)); } dataList.add(row); } return new DataArrayWrapper(dataList, columnMetaData); }
From source file:com.univocity.app.data.Data.java
public void reloadData() { data.clear();// w ww . ja va2s. co m SqlRowSet queryResult = database.getJdbcTemplate().queryForRowSet(selectScript); SqlRowSetMetaData metaData = queryResult.getMetaData(); columnNames = metaData.getColumnNames(); for (int i = 0; i < columnNames.length; i++) { String label = metaData.getColumnLabel(i + 1); if (label != null) { columnNames[i] = label; } } while (queryResult.next()) { Object[] row = new Object[columnNames.length]; for (int i = 0; i < row.length; i++) { row[i] = queryResult.getObject(i + 1); } data.add(row); } }
From source file:ome.testing.OMEData.java
/** * returns a list of results from the sql statement. if there is more than * one column in the result set, a map from column name to Object is * returned, else the Object itself./* w w w . j a v a 2 s . c om*/ * * @param sql * @return */ List runSql(String sql) { JdbcTemplate jt = new JdbcTemplate(ds); SqlRowSet rows = jt.queryForRowSet(sql); List result = new ArrayList(); while (rows.next()) { SqlRowSetMetaData meta = rows.getMetaData(); int count = meta.getColumnCount(); if (count > 1) { Map cols = new HashMap(); String[] names = meta.getColumnNames(); for (int i = 0; i < names.length; i++) { cols.put(names[i], rows.getObject(names[i])); } result.add(cols); } else { result.add(rows.getObject(1)); } } log.debug("SQL:" + sql + "\n\nResult:" + result); return result; }
From source file:org.sipfoundry.sipxconfig.acd.stats.AcdHistoricalStatsImpl.java
public List<String> getReportFields(String reportName) { AcdHistoricalReport report = (AcdHistoricalReport) m_factory.getBean(reportName); Object[] sqlParameters = new Object[] { new Date(0), new Date(0), "" }; SqlRowSet emptySet = getJdbcTemplate().queryForRowSet(report.getQuery() + " limit 0", sqlParameters); SqlRowSetMetaData meta = emptySet.getMetaData(); List<String> names = Arrays.asList(meta.getColumnNames()); return names; }