Example usage for javax.sql RowSetMetaData getColumnCount

List of usage examples for javax.sql RowSetMetaData getColumnCount

Introduction

In this page you can find the example usage for javax.sql RowSetMetaData getColumnCount.

Prototype

int getColumnCount() throws SQLException;

Source Link

Document

Returns the number of columns in this ResultSet object.

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 .ja  va2  s . 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();
}