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

The following are Jave code examples for showing how to use getMetaData() 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: calcite-avatica   File: RemoteDriverTest.java   View Source Code Vote up 7 votes
@Test public void testUnicodeColumnNames() throws Exception {
  final String tableName = "unicodeColumn";
  final String columnName = "\u041d\u043e\u043c\u0435\u0440\u0422\u0435\u043b"
      + "\u0435\u0444\u043e\u043d\u0430"; // PhoneNumber in Russian
  ConnectionSpec.getDatabaseLock().lock();
  try (Connection conn = getLocalConnection();
      Statement stmt = conn.createStatement()) {
    assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName));
    final String sql = "CREATE TABLE " + tableName + "(" + columnName + " integer)";
    assertFalse(stmt.execute(sql));
    final ResultSet results = stmt.executeQuery("SELECT * FROM " + tableName);
    assertNotNull(results);
    ResultSetMetaData metadata = results.getMetaData();
    assertNotNull(metadata);
    String actualColumnName = metadata.getColumnName(1);
    // HSQLDB is going to upper-case the column name
    assertEquals(columnName.toUpperCase(Locale.ROOT), actualColumnName);
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 2
Project: rapidminer   File: DatabaseHandler.java   View Source Code Vote up 7 votes
public static List<Attribute> createAttributes(ResultSet rs) throws SQLException {
    LinkedList attributes = new LinkedList();
    if(rs == null) {
        throw new IllegalArgumentException("Cannot create attributes: ResultSet must not be null!");
    } else {
        ResultSetMetaData metadata;
        try {
            metadata = rs.getMetaData();
        } catch (NullPointerException var7) {
            throw new RuntimeException("Could not create attribute list: ResultSet object seems closed.");
        }

        int numberOfColumns = metadata.getColumnCount();

        for(int column = 1; column <= numberOfColumns; ++column) {
            String name = metadata.getColumnLabel(column);
            Attribute attribute = AttributeFactory.createAttribute(name, getRapidMinerTypeIndex(metadata.getColumnType(column)));
            attributes.add(attribute);
        }

        return attributes;
    }
}
 
Example 3
Project: OpenDiabetes   File: TestViewAsterisks.java   View Source Code Vote up 7 votes
/**
 *  ensures two tables (or views, that is) have the same content
 */
private void ensureEqualContent(String tableNameLHS,
                                String tableNameRHS) throws SQLException {

    ResultSet lhs = m_statement.executeQuery("SELECT * FROM \""
        + tableNameLHS + "\"");
    ResultSet rhs = m_statement.executeQuery("SELECT * FROM \""
        + tableNameRHS + "\"");
    ResultSetMetaData meta = lhs.getMetaData();

    while (lhs.next() && rhs.next()) {
        for (int col = 1; col <= meta.getColumnCount(); ++col) {
            assertEquals("table content does not match: cp. "
                         + tableNameLHS + "-" + tableNameRHS + ", row "
                         + lhs.getRow() + ", col "
                         + col, lhs.getObject(col), rhs.getObject(col));
        }
    }

    // lhs should be after last, rhs still on last
    assertTrue("row count does not match: " + tableNameLHS + "-"
               + tableNameRHS, lhs.isAfterLast() && rhs.isLast());
}
 
Example 4
Project: mybatisx   File: DefaultSqlRunner.java   View Source Code Vote up 7 votes
/**
 * 得到结果集总数
 * @param ps
 * @return
 * @throws SQLException
 */
private long getTotal(PreparedStatement ps) throws SQLException {
 long total=-1;
 ResultSet rs=null;
 ResultSetMetaData rsmd=null;
 String columnName=null;
 
 while(ps.getMoreResults()){
  rs= ps.getResultSet();
  	  rsmd = rs.getMetaData();
        for (int i = 0, n = rsmd.getColumnCount(); i < n; i++) {
      	  columnName=rsmd.getColumnLabel(i + 1);
      	  if(columnName.equalsIgnoreCase(COLUMN_TOTAL_NAME)){
      		  while (rs.next()) {
      			  total=rs.getLong(columnName);
    	  }
      		  break;
      	  }
        }
    }
 return total;
}
 
Example 5
Project: dremio-oss   File: Drill2288GetColumnsMetadataWhenNoRowsTest.java   View Source Code Vote up 7 votes
/** (Failed before (because TABLE_NAME test is pushed down).) */
@Test
public void testInfoSchemaTablesZeroRowsBy_TABLE_NAME_works()
    throws Exception {
  Statement stmt = connection.createStatement();
  ResultSet results =
      stmt.executeQuery(
          "SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME = ''" );

  // Result set should still have columns even though there are no rows:
  ResultSetMetaData metadata = results.getMetaData();
  assertThat( "ResultSetMetaData.getColumnCount() should have been > 0",
              metadata.getColumnCount(), not( equalTo( 0 ) ) );

  assertThat( "Unexpected non-empty results.  Test rot?",
              false, equalTo( results.next() ) );
}
 
Example 6
Project: paraflow   File: DBConnection.java   View Source Code Vote up 7 votes
public ResultList executeQuery(String sqlStatement) throws SQLExecutionException
{
    ResultSet resultSet;
    ResultList resultList;
    try {
        Statement stmt = connection.createStatement();
        resultSet = stmt.executeQuery(sqlStatement);
        ResultSetMetaData rsMetadata = resultSet.getMetaData();
        resultList = convert(resultSet, rsMetadata.getColumnCount());
        resultSet.close();
        stmt.close();
    }
    catch (SQLException e) {
        throw new SQLExecutionException(sqlStatement);
    }
    return  resultList;
}
 
Example 7
Project: morf   File: TestSqlStatements.java   View Source Code Vote up 6 votes
/**
 * Checks if parametrised query execution is working correctly.
 */
@Test
public void shouldExecuteParametrisedQuery()  {
  SqlScriptExecutor executor = sqlScriptExecutorProvider.get(new LoggingSqlScriptVisitor());

  SelectStatement testSelect = select(field("alfaDate1"), field("alfaDate2"), literal(123))
                               .from(tableRef("DateTable")).where(eq(field("alfaDate1"), parameter("firstDateParam").type(DataType.BIG_INTEGER)));;
  Iterable<SqlParameter> parameterMetadata = ImmutableList.of(parameter(column("firstDateParam", DataType.STRING)));
  RecordBuilder parameterData = DataSetUtils.record().setString("firstDateParam", "20040609");
  ResultSetProcessor<List<List<String>>> resultSetProcessor = new ResultSetProcessor<List<List<String>>>() {
    /**
     * Takes all rows and puts into two-dimension String array.
     */
    @Override
    public List<List<String>> process(ResultSet resultSet) throws SQLException {
      Builder<List<String>> builder = ImmutableList.<List<String>>builder();
      ResultSetMetaData metaData = resultSet.getMetaData();
      int columnCount = metaData.getColumnCount();

      while (resultSet.next()) {
        List<String> rowBuilder = new LinkedList<>();
        for (int columnNumber = 1; columnNumber < columnCount + 1; columnNumber++) {
          String stringifiezedCell = resultSet.getString(columnNumber);
          rowBuilder.add(stringifiezedCell);
        }
        builder.add(rowBuilder);
      }
      return builder.build();
    }
  };
  List<List<String>> result = executor.executeQuery(testSelect, parameterMetadata, parameterData, connection, resultSetProcessor);

  assertEquals(ImmutableList.of(ImmutableList.of("20040609","20040813", "123"), ImmutableList.of("20040609","20040609", "123") , ImmutableList.of("20040609","20040610", "123")), result);
}
 
Example 8
Project: OpenDiabetes   File: TriggerSample.java   View Source Code Vote up 6 votes
private static void dumpTable(String tn) throws SQLException {

        Connection        conn  = getConnection();
        Statement         stmt  = conn.createStatement();
        ResultSet         rs    = stmt.executeQuery("select * from " + tn);
        ResultSetMetaData rsmd  = rs.getMetaData();
        int               count = rsmd.getColumnCount();

        out.println();
        out.println("****************************************");
        out.println("DUMP FOR TABLE: " + tn);
        out.println("****************************************");
        out.flush();

        while (rs.next()) {
            out.print("[");

            for (int i = 1; i <= count; i++) {
                out.print(rs.getString(i));

                if (i < count) {
                    out.print(" : ");
                }
            }

            out.println("]");
        }

        out.println();
        out.flush();
        rs.close();
        stmt.close();
        conn.close();
    }
 
Example 9
Project: the-vigilantes   File: MetaDataRegressionTest.java   View Source Code Vote up 5 votes
private void checkReturnedColumnsForBug44451(String stepDescription, String methodName, List<String> expectedFields, ResultSet resultSetToCheck)
        throws Exception {
    ResultSetMetaData rsMetaData = resultSetToCheck.getMetaData();
    int numberOfColumns = rsMetaData.getColumnCount();

    assertEquals(stepDescription + ", wrong column count in method '" + methodName + "'.", expectedFields.size(), numberOfColumns);
    for (int i = 0; i < numberOfColumns; i++) {
        int position = i + 1;
        assertEquals(stepDescription + ", wrong column at position '" + position + "' in method '" + methodName + "'.", expectedFields.get(i),
                rsMetaData.getColumnName(position));
    }
    rs.close();
}
 
Example 10
Project: ProyectoPacientes   File: MetaDataRegressionTest.java   View Source Code Vote up 5 votes
private void checkTypes(ResultSet rsToCheck, int[] types) throws Exception {
    ResultSetMetaData rsmd = rsToCheck.getMetaData();
    assertEquals(types.length, rsmd.getColumnCount());
    for (int i = 0; i < types.length; i++) {
        String expectedType = TYPES_MAP.get(new Integer(types[i]));
        String actualType = TYPES_MAP.get(new Integer(rsmd.getColumnType(i + 1)));
        assertNotNull(expectedType);
        assertNotNull(actualType);
        assertEquals("Unexpected type in column " + (i + 1), expectedType, actualType);
    }
}
 
Example 11
Project: calcite-avatica   File: RemoteDriverMockTest.java   View Source Code Vote up 5 votes
@Test public void testTables() throws Exception {
  final Connection connection = getMockConnection();
  final ResultSet resultSet =
      connection.getMetaData().getTables(null, null, null, new String[0]);
  assertFalse(resultSet.next());
  final ResultSetMetaData metaData = resultSet.getMetaData();
  assertTrue(metaData.getColumnCount() >= 3);
  assertEquals("TABLE_CAT", metaData.getColumnName(1));
  assertEquals("TABLE_SCHEM", metaData.getColumnName(2));
  assertEquals("TABLE_NAME", metaData.getColumnName(3));
  resultSet.close();
  connection.close();
}
 
Example 12
Project: azeroth   File: JDBCUtils.java   View Source Code Vote up 5 votes
/**
 * Query a single record
 *
 * @param sql
 * @param args
 * @return List<Map<String,Object>>
 */
public static List<Map<String, Object>> queryForList(String sql, Object... args) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    Connection con = null;
    ResultSet rs = null;
    PreparedStatement ps = null;
    try {
        con = getconnnection();
        ps = con.prepareStatement(sql);
        if (args != null) {
            for (int i = 0; i < args.length; i++) {
                ps.setObject((i + 1), args[i]);
            }
        }
        rs = ps.executeQuery();
        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();
        while (rs.next()) {
            Map<String, Object> map = new HashMap<String, Object>();
            for (int i = 1; i <= columnCount; i++) {
                map.put(rsmd.getColumnLabel(i), rs.getObject(i));
            }
            result.add(map);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        close(rs, ps, con);
    }
    return result;
}
 
Example 13
Project: My-Blog   File: DataTable.java   View Source Code Vote up 5 votes
public static DataTable parse(ResultSet resultSet) throws SQLException {
	ResultSetMetaData metaData = resultSet.getMetaData();
	DataTable dataTable = new DataTable();
	dataTable.columns = new ColumnCollection();

	int colCount = metaData.getColumnCount();
	for (int i = 1; i <= colCount; i++) {
		Column column = new Column();
		column.setCatalogName(metaData.getCatalogName(i));
		column.setColumnClassName(metaData.getColumnClassName(i));
		column.setDisplaySize(metaData.getColumnDisplaySize(i));
		column.setLabel(metaData.getColumnLabel(i));
		column.setName(metaData.getColumnName(i));
		column.setPrecision(metaData.getPrecision(i));
		column.setScale(metaData.getScale(i));
		column.setSchemaName(metaData.getSchemaName(i));
		column.setTableName(metaData.getTableName(i));
		column.setType(metaData.getColumnType(i));
		column.setTypeName(metaData.getColumnTypeName(i));
		dataTable.columns.add(column);
	}

	while (resultSet.next()) {
		Object[] data = new Object[colCount];
		for (int i = 1; i <= data.length; i++) {
			data[i - 1] = resultSet.getObject(i);
		}
		dataTable.add(new Row(dataTable, data));
	}
	resultSet.close();
	return dataTable;
}
 
Example 14
Project: uavstack   File: ResultConverter.java   View Source Code Vote up 5 votes
public <T> T convert(ResultSet rs, Class<T> cls) throws SQLException {

        T obj = null;
        boolean isNull = true;
        try {

            ResultSetMetaData md = rs.getMetaData();
            List<String> list = new ArrayList<String>();
            for (int j = 1; j <= md.getColumnCount(); j++) {
                list.add(md.getColumnName(j));
            }

            obj = cls.newInstance();
            Field[] fields = obj.getClass().getDeclaredFields();
            for (Field field : fields) {
                String fieldName = field.getName();
                String columnName = convertColumnName(fieldName);
                if (list.contains(columnName)) {
                    isNull = false;
                    @SuppressWarnings("rawtypes")
                    Class fieldType = field.getType();
                    field.setAccessible(true);
                    field.set(obj, convertColumnValue(fieldType.getName(), columnName, rs));
                }
            }

        }
        catch (Exception e) {
            // logger.error("Convert DB Data FAIL", e);
        }
        return isNull ? null : obj;
    }
 
Example 15
Project: calcite-avatica   File: RemoteDriverTest.java   View Source Code Vote up 5 votes
private void checkStatementExecute(Connection connection,
    boolean prepare, int maxRowCount) throws SQLException {
  final String sql = "select * from (\n"
      + "  values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)";
  final Statement statement;
  final ResultSet resultSet;
  final ParameterMetaData parameterMetaData;
  if (prepare) {
    final PreparedStatement ps = connection.prepareStatement(sql);
    statement = ps;
    ps.setMaxRows(maxRowCount);
    parameterMetaData = ps.getParameterMetaData();
    assertTrue(ps.execute());
    resultSet = ps.getResultSet();
  } else {
    statement = connection.createStatement();
    statement.setMaxRows(maxRowCount);
    parameterMetaData = null;
    assertTrue(statement.execute(sql));
    resultSet = statement.getResultSet();
  }
  if (parameterMetaData != null) {
    assertThat(parameterMetaData.getParameterCount(), equalTo(0));
  }
  final ResultSetMetaData metaData = resultSet.getMetaData();
  assertEquals(2, metaData.getColumnCount());
  assertEquals("C1", metaData.getColumnName(1));
  assertEquals("C2", metaData.getColumnName(2));
  for (int i = 0; i < maxRowCount || (maxRowCount == 0 && i < 3); i++) {
    assertTrue(resultSet.next());
  }
  assertFalse(resultSet.next());
  resultSet.close();
  statement.close();
  connection.close();
}
 
Example 16
Project: ProyectoPacientes   File: ResultSetUtil.java   View Source Code Vote up 4 votes
public static StringBuilder appendResultSetSlashGStyle(StringBuilder appendTo, ResultSet rs) throws SQLException {
    ResultSetMetaData rsmd = rs.getMetaData();

    int numFields = rsmd.getColumnCount();
    int maxWidth = 0;

    String[] fieldNames = new String[numFields];

    for (int i = 0; i < numFields; i++) {
        fieldNames[i] = rsmd.getColumnLabel(i + 1);

        if (fieldNames[i].length() > maxWidth) {
            maxWidth = fieldNames[i].length();
        }
    }

    int rowCount = 1;

    while (rs.next()) {
        appendTo.append("*************************** ");
        appendTo.append(rowCount++);
        appendTo.append(". row ***************************\n");

        for (int i = 0; i < numFields; i++) {
            int leftPad = maxWidth - fieldNames[i].length();

            for (int j = 0; j < leftPad; j++) {
                appendTo.append(" ");
            }

            appendTo.append(fieldNames[i]);
            appendTo.append(": ");

            String stringVal = rs.getString(i + 1);

            if (stringVal != null) {
                appendTo.append(stringVal);
            } else {
                appendTo.append("NULL");
            }

            appendTo.append("\n");
        }

        appendTo.append("\n");
    }

    return appendTo;
}
 
Example 17
Project: elastic-db-tools-for-java   File: MultiShardStatement.java   View Source Code Vote up 4 votes
private MultiShardException validateResultSet(ResultSet r,
        ShardLocation loc) throws SQLException {
    if (r.isClosed()) {
        // ResultSet is already closed. Hence adding an exception in its place.
        return new MultiShardException(loc, new MultiShardResultSetClosedException(
                String.format("The result set for '%1$s' was closed and could not be added.", loc.getDatabase())));
    }
    ResultSetMetaData m = r.getMetaData();
    if (m == null || m.getColumnCount() == 0) {
        // ResultSet does not have proper metadata to read.
        return new MultiShardException(loc, new MultiShardResultSetInternalException(
                String.format("The result set for '%1$s' does not have proper metadata to read and could not be added.", loc.getDatabase())));
    }
    if (this.schemaComparisonTemplate == null) {
        this.schemaComparisonTemplate = r.getMetaData();
        return null;
    }
    for (int i = 1; i <= m.getColumnCount(); i++) {
        // Get the designated column's name.
        String expectedName = this.schemaComparisonTemplate.getColumnName(i);
        String actualName = m.getColumnName(i);
        if (!Objects.equals(expectedName, actualName)) {
            return new MultiShardException(loc, new MultiShardSchemaMismatchException(loc,
                    String.format("Expected schema column name %1$s, but encountered schema column name %2$s.", expectedName, actualName)));
        }

        // Retrieves the designated column's SQL type.
        if (!Objects.equals(this.schemaComparisonTemplate.getColumnType(i), m.getColumnType(i))) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched SQL type values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    this.schemaComparisonTemplate.getColumnTypeName(i), m.getColumnTypeName(i))));
        }

        // Get the designated column's specified column size.
        int expectedPrecision = this.schemaComparisonTemplate.getPrecision(i);
        int actualPrecision = m.getPrecision(i);
        if (!Objects.equals(expectedPrecision, actualPrecision)) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    expectedPrecision, actualPrecision)));
        }

        // Indicates the nullability of values in the designated column.
        int expectedNullableValue = this.schemaComparisonTemplate.isNullable(i);
        int actualNullableValue = m.isNullable(i);
        if (!Objects.equals(expectedNullableValue, actualNullableValue)) {
            return new MultiShardException(loc,
                    new MultiShardSchemaMismatchException(loc,
                            String.format("Mismatched nullability values for column %1$s. Expected: %2$s. Actual: %3$s", actualName,
                                    NullableValue.forValue(expectedNullableValue), NullableValue.forValue(actualNullableValue))));
        }
    }
    return null;
}
 
Example 18
Project: wayf-cloud   File: NestedFieldRowMapper.java   View Source Code Vote up 4 votes
@Override
public Object mapRow(ResultSet resultSet, int i) throws SQLException {
    LOG.debug("Mapping row {}", i);
    ResultSetMetaData metadata = resultSet.getMetaData();

    int numColumns = metadata.getColumnCount();

    Map<String, Object> resultSetValues = new HashMap<>();

    for (int columnIndex = 1; columnIndex <= numColumns; columnIndex++) {
        int columnType = metadata.getColumnType(columnIndex);
        String columnLabel = metadata.getColumnLabel(columnIndex);

        switch (columnType) {
            case Types.DOUBLE:
            case Types.DECIMAL:
                double doubleValue = resultSet.getDouble(columnLabel);

                if (!resultSet.wasNull()) {
                    resultSetValues.put(columnLabel, doubleValue);
                }
                resultSetValues.put(columnLabel, resultSet.getDouble(columnLabel));
                break;
            case Types.INTEGER:
            case Types.TINYINT:
            case Types.BIGINT:
                int intValue = resultSet.getInt(columnLabel);

                if (!resultSet.wasNull()) {
                    resultSetValues.put(columnLabel, intValue);
                }
                break;
            case Types.TIMESTAMP:
            case Types.DATE:
                resultSetValues.put(columnLabel, resultSet.getTimestamp(columnLabel));
                break;
            case Types.CHAR:
            case Types.VARCHAR:
                resultSetValues.put(columnLabel, resultSet.getString(columnLabel));
                break;
            default:
                throw new RuntimeException("Could not determine return type for column [" + columnLabel + "] with type [" + columnType + "]");
        }
    }

    LOG.debug("Found resultset values [{}]", resultSetValues);

    return beanMapper.map(resultSetValues, returnType);
}
 
Example 19
Project: KBUnitTest   File: ShadowSQLiteDirectCursorDriver.java   View Source Code Vote up 4 votes
public Cursor query(ShadowSQLiteDatabase.CursorFactory factory, String[] selectionArgs) {
//        ShadowSQLiteQuery query  = new ShadowSQLiteQuery(mDatabase, mSql, selectionArgs, mCancellationSignal);
        try {
            String querySql = KbSqlParser.bindArgs(mSql, selectionArgs);

            mDatabase.debug(querySql);

            Connection connection = mDatabase.getConnection();
            Statement  statement  = connection.createStatement();

            ResultSet         rs          = statement.executeQuery(querySql);
            ResultSetMetaData metaData    = rs.getMetaData();
            int               columnCount = metaData.getColumnCount();
            List<String>      columns     = new ArrayList<>();

            // column name数组, colum从1开始
            for (int i = 1; i < columnCount + 1; i++) {
                String name = metaData.getColumnName(i);

                columns.add(name);
            }

            // 结果集合
            List<List<Object>> datas = new ArrayList<>();

            while (rs.next()) {
                List<Object> data = new ArrayList<>();

                // ResultSet colum从1开始
                for (int i = 1; i < columnCount + 1; i++) {
                    Object value = rs.getObject(i);

                    data.add(value);
                }

                datas.add(data);
            }

            rs.close();
            statement.close();

            ShadowCursor shadowCursor = new ShadowCursor(columns, datas);

            return shadowCursor;
        } catch (RuntimeException ex) {
            throw ex;
        } catch (java.sql.SQLException e) {
            throw new android.database.SQLException(e.getMessage());
        }

//        mQuery = query;
    }
 
Example 20
Project: OpenVertretung   File: CallableStatementTest.java   View Source Code Vote up 2 votes
/**
 * Tests functioning of output parameters.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testResultSet() throws Exception {
    if (versionMeetsMinimum(5, 0)) {
        CallableStatement storedProc = null;

        createTable("testSpResultTbl1", "(field1 INT)");
        this.stmt.executeUpdate("INSERT INTO testSpResultTbl1 VALUES (1), (2)");
        createTable("testSpResultTbl2", "(field2 varchar(255))");
        this.stmt.executeUpdate("INSERT INTO testSpResultTbl2 VALUES ('abc'), ('def')");

        createProcedure("testSpResult", "()\nBEGIN\nSELECT field2 FROM testSpResultTbl2 WHERE field2='abc';\n"
                + "UPDATE testSpResultTbl1 SET field1=2;\nSELECT field2 FROM testSpResultTbl2 WHERE field2='def';\nend\n");

        storedProc = this.conn.prepareCall("{call testSpResult()}");

        storedProc.execute();

        this.rs = storedProc.getResultSet();

        ResultSetMetaData rsmd = this.rs.getMetaData();

        assertTrue(rsmd.getColumnCount() == 1);
        assertTrue("field2".equals(rsmd.getColumnName(1)));
        assertTrue(rsmd.getColumnType(1) == Types.VARCHAR);

        assertTrue(this.rs.next());

        assertTrue("abc".equals(this.rs.getString(1)));

        // TODO: This does not yet work in MySQL 5.0
        // assertTrue(!storedProc.getMoreResults());
        // assertTrue(storedProc.getUpdateCount() == 2);
        assertTrue(storedProc.getMoreResults());

        ResultSet nextResultSet = storedProc.getResultSet();

        rsmd = nextResultSet.getMetaData();

        assertTrue(rsmd.getColumnCount() == 1);
        assertTrue("field2".equals(rsmd.getColumnName(1)));
        assertTrue(rsmd.getColumnType(1) == Types.VARCHAR);

        assertTrue(nextResultSet.next());

        assertTrue("def".equals(nextResultSet.getString(1)));

        nextResultSet.close();

        this.rs.close();

        storedProc.execute();
    }
}