Example usage for javax.sql.rowset WebRowSet getMetaData

List of usage examples for javax.sql.rowset WebRowSet getMetaData

Introduction

In this page you can find the example usage for javax.sql.rowset WebRowSet getMetaData.

Prototype

ResultSetMetaData getMetaData() throws SQLException;

Source Link

Document

Retrieves the number, types and properties of this ResultSet object's columns.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar);");
    st.executeUpdate("create view surveyView as (select * from survey);");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')");

    String sqlQuery = "SELECT * FROM survey";
    WebRowSet webRS = new WebRowSetImpl();
    webRS.setCommand(sqlQuery);//w ww . j ava  2s.  c o  m
    webRS.execute(conn);

    // create RowSetMetaData object
    RowSetMetaData rsMD = (RowSetMetaData) webRS.getMetaData();
    System.out.println("rsMD=" + rsMD);
    if (rsMD == null) {
        System.out.println("vendor does not support RowSetMetaData");
    } else {
        int columnCount = rsMD.getColumnCount();
        System.out.println("columnCount=" + columnCount);
    }
    conn.close();
}

From source file:at.ac.univie.isc.asio.engine.sql.JooqEngineTest.java

@Test
public void empty_select_to_webrowset_header() throws Exception {
    final Command params = CommandBuilder.empty().language(Language.SQL)
            .single(JooqEngine.PARAM_QUERY, REFERENCE_EMPTY).accept(WEBROWSET_TYPE).build();
    final byte[] raw = performInvocationWith(params);
    final WebRowSet wrs = parseWebRowSet(raw);
    assertThat(wrs.size(), is(0));//from w ww .j a va 2 s .  com
    final ResultSetMetaData context = wrs.getMetaData();
    for (int index = 0; index < COLUMN_NAMES.length; index++) {
        assertThat(context.getColumnName(index + 1), is(COLUMN_NAMES[index]));
    }
}