Package java.sql

Examples of java.sql.ResultSetMetaData


        return s;
    }

    private void writeResultSet(String sql, ResultSet rs) throws Exception {
        boolean ordered = StringUtils.toLowerEnglish(sql).indexOf("order by") >= 0;
        ResultSetMetaData meta = rs.getMetaData();
        int len = meta.getColumnCount();
        int[] max = new int[len];
        String[] head = new String[len];
        for (int i = 0; i < len; i++) {
            String label = formatString(meta.getColumnLabel(i + 1));
            max[i] = label.length();
            head[i] = label;
        }
        result.clear();
        while (rs.next()) {
View Full Code Here


        }
        return result;
    }

    protected static Object[] toArray(final ResultSet rs) throws SQLException {
        ResultSetMetaData meta = rs.getMetaData();
        final int cols = meta.getColumnCount();
        final Object[] result = new Object[cols];
        for(int i = 0; i < cols; i++) {
            result[i] = rs.getObject(i + 1);
        }
        return result;
View Full Code Here

        write(lineSeparator);
    }

    public int writeAll(@Nonnull final ResultSet rs, @Nonnull final String nullStr, final boolean includeHeaders)
            throws SQLException {
        final ResultSetMetaData meta = rs.getMetaData();
        if(includeHeaders) {
            writeColumnNames(meta);
        }
        final int numColumns = meta.getColumnCount();
        final String[] columnClasses = new String[numColumns + 1];
        for(int i = 1; i <= numColumns; i++) {
            String className = meta.getColumnClassName(i);
            columnClasses[i] = JAVA_STRING_CLASS_NAME.equals(className) ? JAVA_STRING_CLASS_NAME
                    : className;
        }
        int numRows = 0;
        while(rs.next()) {
View Full Code Here

      connection.getMetaData();
      Statement statement = connection.createStatement();
      boolean hasResults = statement.execute(sql);
      if (hasResults) {
        ResultSet results = statement.getResultSet();
        ResultSetMetaData metadata = results.getMetaData();
        int columns = metadata.getColumnCount();
       
        while(results.next()) {
          for (int i = 0; i < columns; i++) {
            System.out.print(results.getString(i+1));
            System.out.print(",");
View Full Code Here

    private void map(String key, ResultSet rs, boolean railroads) throws Exception {
        ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
        while (rs.next()) {
            HashMap<String, String> map = new HashMap<String, String>();
            ResultSetMetaData meta = rs.getMetaData();
            for (int i = 0; i < meta.getColumnCount(); i++) {
                String k = StringUtils.toLowerEnglish(meta.getColumnLabel(i + 1));
                String value = rs.getString(i + 1);
                value = value.trim();
                map.put(k, PageParser.escapeHtml(value));
            }
            String topic = rs.getString("TOPIC");
View Full Code Here

        }
    }

    private static String readResult(ResultSet rs) throws SQLException {
        StringBuilder b = new StringBuilder();
        ResultSetMetaData meta = rs.getMetaData();
        int columnCount = meta.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            if (i > 0) {
                b.append(",");
            }
            b.append(StringUtils.toUpperEnglish(meta.getColumnLabel(i + 1)));
        }
        b.append(":\n");
        String result = b.toString();
        ArrayList<String> list = New.arrayList();
        while (rs.next()) {
View Full Code Here

        this.sql = sql;
        type = RESULT_SET;
        try {
            rows = New.arrayList();
            header = New.arrayList();
            ResultSetMetaData meta = rs.getMetaData();
            int len = meta.getColumnCount();
            Column[] cols = new Column[len];
            for (int i = 0; i < len; i++) {
                cols[i] = new Column(meta, i + 1);
            }
            while (rs.next()) {
View Full Code Here

        stat.executeUpdate("drop table test");
    }

    private void testPreparedStatementMetaData(Connection conn) throws SQLException {
        PreparedStatement prep = conn.prepareStatement("select * from table(x int = ?, name varchar = ?)");
        ResultSetMetaData meta = prep.getMetaData();
        assertEquals(2, meta.getColumnCount());
        assertEquals("INTEGER", meta.getColumnTypeName(1));
        assertEquals("VARCHAR", meta.getColumnTypeName(2));
        prep = conn.prepareStatement("call 1");
        meta = prep.getMetaData();
        assertEquals(1, meta.getColumnCount());
        assertEquals("INTEGER", meta.getColumnTypeName(1));
    }
View Full Code Here

        rs.next();
        rs.getString("x");
        rs.getString("y");
        rs.close();
        rs = conn.getMetaData().getColumns(null, null, null, null);
        ResultSetMetaData meta = rs.getMetaData();
        int columnCount = meta.getColumnCount();
        String[] columnName = new String[columnCount];
        for (int i = 1; i <= columnCount; i++) {
            // columnName[i - 1] = meta.getColumnLabel(i);
            columnName[i - 1] = meta.getColumnName(i);
        }
        while (rs.next()) {
            for (int i = 0; i < columnCount; i++) {
                rs.getObject(columnName[i]);
            }
View Full Code Here

        rs.updateRow();
        stat.execute("DROP TABLE TEST");
    }

    private void checkPrecision(int expected, String sql) throws SQLException {
        ResultSetMetaData meta = stat.executeQuery(sql).getMetaData();
        assertEquals(expected, meta.getPrecision(1));
    }
View Full Code Here

TOP

Related Classes of java.sql.ResultSetMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.