Search in sources :

Example 6 with SimpleResultSet

use of com.wplatform.ddal.result.SimpleResultSet in project jdbc-shards by wplatform.

the class ValueResultSet method getCopy.

/**
 * Create a result set value for the given result set. The result set will
 * be fully read in memory. The original result set is not closed.
 *
 * @param rs      the result set
 * @param maxrows the maximum number of rows to read (0 to just read the
 *                meta data)
 * @return the value
 */
public static ValueResultSet getCopy(ResultSet rs, int maxrows) {
    try {
        ResultSetMetaData meta = rs.getMetaData();
        int columnCount = meta.getColumnCount();
        SimpleResultSet simple = new SimpleResultSet();
        simple.setAutoClose(false);
        ValueResultSet val = new ValueResultSet(simple);
        for (int i = 0; i < columnCount; i++) {
            String name = meta.getColumnLabel(i + 1);
            int sqlType = meta.getColumnType(i + 1);
            int precision = meta.getPrecision(i + 1);
            int scale = meta.getScale(i + 1);
            simple.addColumn(name, sqlType, precision, scale);
        }
        for (int i = 0; i < maxrows && rs.next(); i++) {
            Object[] list = new Object[columnCount];
            for (int j = 0; j < columnCount; j++) {
                list[j] = rs.getObject(j + 1);
            }
            simple.addRow(list);
        }
        return val;
    } catch (SQLException e) {
        throw DbException.convert(e);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SimpleResultSet(com.wplatform.ddal.result.SimpleResultSet) SQLException(java.sql.SQLException)

Example 7 with SimpleResultSet

use of com.wplatform.ddal.result.SimpleResultSet in project jdbc-shards by wplatform.

the class CallableStatementTestCase method testCall.

/**
 * This method is called via reflection from the database.
 *
 * @param conn the connection
 * @param a the value a
 * @param b the value b
 * @param c the value c
 * @param d the value d
 * @return a result set
 */
public static ResultSet testCall(Connection conn, int a, String b, Timestamp c, Timestamp d) throws SQLException {
    SimpleResultSet rs = new SimpleResultSet();
    rs.addColumn("A", Types.INTEGER, 0, 0);
    rs.addColumn("B", Types.VARCHAR, 0, 0);
    rs.addColumn("C", Types.TIMESTAMP, 0, 0);
    rs.addColumn("D", Types.TIMESTAMP, 0, 0);
    if ("jdbc:columnlist:connection".equals(conn.getMetaData().getURL())) {
        return rs;
    }
    rs.addRow(a * 2, b.toUpperCase(), new Timestamp(c.getTime() + 1), d);
    return rs;
}
Also used : SimpleResultSet(com.wplatform.ddal.result.SimpleResultSet) Timestamp(java.sql.Timestamp)

Aggregations

SimpleResultSet (com.wplatform.ddal.result.SimpleResultSet)7 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1