List of usage examples for javax.sql RowSet next
boolean next() throws SQLException;
From source file:Main.java
static void displayRowSet(RowSet rs) throws SQLException { while (rs.next()) { System.out.println(rs.getRow() + " - " + rs.getString("col1") + ":" + rs.getInt("col2") + ":" + rs.getString("col3")); }// w w w. j a va 2s . c om }
From source file:com.oracle.tutorial.jdbc.JdbcRowSetSample.java
private void outputRowSet(RowSet rs) throws SQLException { rs.beforeFirst();//from w ww .ja va 2 s .com while (rs.next()) { String coffeeName = rs.getString(1); int supplierID = rs.getInt(2); float price = rs.getFloat(3); int sales = rs.getInt(4); int total = rs.getInt(5); System.out.println(coffeeName + ", " + supplierID + ", " + price + ", " + sales + ", " + total); } }
From source file:org.aludratest.cloud.web.report.SqlBean.java
public synchronized void execute() { resultColumns = null;/*from w w w . j a v a2 s.c o m*/ resultRows = null; if (sql == null) { return; } sql = sql.trim(); while (sql.endsWith(";")) { sql = sql.substring(0, sql.length() - 1); } // easy basic check if (!sql.toLowerCase(Locale.US).startsWith("select ")) { FacesContext.getCurrentInstance().addMessage(null, JSFUtil.createErrorMessage("Only SELECT statements are allowed")); return; } try { RowSet rs = CloudManagerApplicationHolder.getInstance().getDatabase().populateQuery(sql); resultColumns = new ArrayList<String>(); ResultSetMetaData meta = rs.getMetaData(); for (int i = 1; i <= meta.getColumnCount(); i++) { resultColumns.add(meta.getColumnName(i)); } rs.beforeFirst(); resultRows = new ArrayList<Map<String, String>>(); while (rs.next()) { Map<String, String> row = new HashMap<String, String>(); // TODO nicer formatting etc. for (String col : resultColumns) { row.put(col, rs.getString(col)); } resultRows.add(row); } } catch (SQLException se) { FacesContext.getCurrentInstance().addMessage(null, JSFUtil.createErrorMessage("SQLException: " + se.getMessage())); } }