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.example.querybuilder.server.Jdbc.java
public static Object getObject(ResultSet resultSet, int columnNumber) { try {//from w w w . j ava2 s. c om return resultSet.getObject(columnNumber); } catch (SQLException e) { throw new SqlRuntimeException(e); } }
From source file:com.example.querybuilder.server.Jdbc.java
public static boolean isNull(ResultSet resultSet, int columnNumber) { try {/* www .ja v a 2 s. co m*/ return resultSet.getObject(columnNumber) == null; } catch (SQLException e) { throw new SqlRuntimeException(e); } }
From source file:modelo.ApiManager.java
public static List resultSetToArrayList(ResultSet rs) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); ArrayList list = new ArrayList(); while (rs.next()) { HashMap row = new HashMap(columns); for (int i = 1; i <= columns; ++i) { row.put(md.getColumnName(i), rs.getObject(i)); }//from w ww.ja v a 2 s . c om list.add(row); } return list; }
From source file:com.bt.aloha.testing.DbTestCase.java
private static String dump(ResultSet rs) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int colmax = meta.getColumnCount(); Object o = null;/*from w w w .jav a 2s. c o m*/ StringBuffer sb = new StringBuffer(); for (; rs.next();) { for (int i = 0; i < colmax; i++) { o = rs.getObject(i + 1); if (o != null) sb.append(o.toString()); else sb.append("null"); if (i < colmax - 1) sb.append(" "); } if (!rs.isLast()) sb.append("\n"); } return sb.toString(); }
From source file:com.wavemaker.runtime.data.util.JDBCUtils.java
public static Object runSql(String sql[], String url, String username, String password, String driverClassName, Log logger, boolean isDDL) { Connection con = getConnection(url, username, password, driverClassName); try {//ww w. ja va 2 s . co m try { con.setAutoCommit(true); } catch (SQLException ex) { throw new DataServiceRuntimeException(ex); } Statement s = con.createStatement(); try { try { for (String stmt : sql) { if (logger != null && logger.isInfoEnabled()) { logger.info("Running " + stmt); } s.execute(stmt); } if (!isDDL) { ResultSet r = s.getResultSet(); List<Object> rtn = new ArrayList<Object>(); while (r.next()) { // getting only the first col is pretty unuseful rtn.add(r.getObject(1)); } return rtn.toArray(new Object[rtn.size()]); } } catch (Exception ex) { if (logger != null && logger.isErrorEnabled()) { logger.error(ex.getMessage()); } throw ex; } } finally { try { s.close(); } catch (Exception ignore) { } } } catch (Exception ex) { if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } else { throw new DataServiceRuntimeException(ex); } } finally { try { con.close(); } catch (Exception ignore) { } } return null; }
From source file:tds.assessment.repositories.impl.StrandQueryRepositoryImpl.java
private static Strand buildStrandFromResultSet(final ResultSet rs) throws SQLException { return new Strand.Builder().withName(rs.getString("name")).withKey(rs.getString("_key")) .withMinItems(rs.getInt("minitems")).withMaxItems(rs.getInt("maxitems")) // calling getObject() and casting to Float because .getFloat() defaults to 0 if null .withAdaptiveCut((Float) rs.getObject("adaptivecut")).withSegmentKey(rs.getString("segmentKey")) .withStrictMax(rs.getBoolean("isstrictmax")).withBpWeight(rs.getFloat("bpweight")) .withStartInfo((Float) rs.getObject("startInfo")).withScalar((Float) rs.getObject("scalar")) .withPrecisionTarget((Float) rs.getObject("precisionTarget")) .withPrecisionTargetMetWeight((Float) rs.getObject("precisionTargetMetWeight")) .withPrecisionTargetNotMetWeight((Float) rs.getObject("precisionTargetNotMetWeight")).build(); }
From source file:Student.java
public static void checkData() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:hsqldb:data/tutorial", "sa", ""); Statement st = conn.createStatement(); ResultSet mrs = conn.getMetaData().getTables(null, null, null, new String[] { "TABLE" }); while (mrs.next()) { String tableName = mrs.getString(3); System.out.println("\n\n\n\nTable Name: "+ tableName); ResultSet rs = st.executeQuery("select * from " + tableName); ResultSetMetaData metadata = rs.getMetaData(); while (rs.next()) { System.out.println(" Row:"); for (int i = 0; i < metadata.getColumnCount(); i++) { System.out.println(" Column Name: "+ metadata.getColumnLabel(i + 1)+ ", "); System.out.println(" Column Type: "+ metadata.getColumnTypeName(i + 1)+ ": "); Object value = rs.getObject(i + 1); System.out.println(" Column Value: "+value+"\n"); }/*from w ww. j ava 2s. c o m*/ } } }
From source file:com.adaptris.jdbc.JdbcResultSetImpl.java
private static JdbcResultRow mapRow(ResultSet resultSet) throws SQLException { ResultSetMetaData rsmd = resultSet.getMetaData(); int columnCount = rsmd.getColumnCount(); JdbcResultRow row = new JdbcResultRow(); for (int counter = 1; counter <= columnCount; counter++) { row.setFieldValue(StringUtils.defaultIfEmpty(rsmd.getColumnLabel(counter), rsmd.getColumnName(counter)), resultSet.getObject(counter), rsmd.getColumnType(counter)); }/* w ww . ja va 2 s. co m*/ return row; }
From source file:com.mg.framework.utils.DatabaseUtils.java
/** * ? ??/*from w w w . j a v a 2s.co m*/ * * @param sequenceName ?? * @return ? */ public static Object getSequenceNextValue(String sequenceName) { String sql; switch (getDBMSType()) { case FIREBIRD: case INTERBASE: sql = "select gen_id(" + sequenceName + ", 1) from RDB$DATABASE"; break; case POSTGRESQL: sql = "select nextval('" + sequenceName + "')"; break; case ORACLE: sql = "select " + sequenceName + ".nextval from dual"; break; default: throw new UnsupportedOperationException("Unknown database"); } List<Object> list = JdbcTemplate.getInstance().query(sql, new Object[] {}, new RowMapper<Object>() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getObject(1); } }); return list.get(0); }
From source file:com.splout.db.common.SQLiteJDBCManager.java
private static List<HashMap<String, Object>> convertResultSetToList(ResultSet rs, int maxResults) throws SQLException { ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>(); while (rs.next() && list.size() < maxResults) { HashMap<String, Object> row = new HashMap<String, Object>(columns); for (int i = 1; i <= columns; ++i) { row.put(md.getColumnName(i), rs.getObject(i)); }//from w w w. j a v a2s .c o m list.add(row); } if (list.size() == maxResults) { throw new SQLException("Hard limit on number of results reached (" + maxResults + "), please use a LIMIT for this query."); } return list; }