Java Code Examples for java.sql.ResultSet.findColumn()

The following are Jave code examples for showing how to use findColumn() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: parabuild-ci   File: ZaurusTableForm.java   View Source Code Vote up 5 votes
private void fillZChoice(ZaurusChoice zc, String tab, String col) {

        try {
            if (cConn == null) {
                return;
            }

            Statement stmt = cConn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT * FROM " + tab
                                             + " ORDER BY " + col);
            ResultSetMetaData rsmd            = rs.getMetaData();
            int               numberOfColumns = rsmd.getColumnCount();
            int               colIndex        = rs.findColumn(col);

            while (rs.next()) {
                String tmp = "";

                for (int i = 1; i <= numberOfColumns; i++) {
                    if (i > 1) {
                        tmp += "; ";
                    }

                    tmp += rs.getString(i);
                }    // end of for (int i=1; i<=numberOfColumns; i++)

                zc.add(tmp, rs.getString(colIndex));
            }

            rs.close();
        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e.getMessage());
        }            // end of try-catch
    }
 
Example 2
Project: morf   File: ResultSetMetadataSorter.java   View Source Code Vote up 5 votes
/**
 * Creates a copy of an {@link Iterable} of columns, where the copy is sorted such that the
 * columns appear in the same order as they do in the supplied {@link ResultSet}.
 *
 * @param columns Columns expected.
 * @param resultSet The result set containing the values.
 * @return The sorted columns.
 */
public static Collection<Column> sortedCopy(Iterable<Column> columns, ResultSet resultSet) {
  Column[] result = new Column[Iterables.size(columns)];
  for (Column column : columns) {
    try {
      result[resultSet.findColumn(column.getName()) - 1] = column;
    } catch(SQLException ex) {
      throw new IllegalStateException("Could not retrieve column [" + column.getName() + "]", ex);
    }
  }
  return Collections.unmodifiableCollection(Arrays.asList(result));
}