Example usage for javax.sql.rowset WebRowSet size

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

Introduction

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

Prototype

public int size();

Source Link

Document

Returns the number of rows in this CachedRowSet object.

Usage

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

@Test
public void valid_select_to_webrowset_content() throws Exception {
    final Command params = CommandBuilder.empty().language(Language.SQL)
            .single(JooqEngine.PARAM_QUERY, REFERENCE_SELECT).accept(WEBROWSET_TYPE).build();
    final byte[] raw = performInvocationWith(params);
    final WebRowSet wrs = parseWebRowSet(raw);
    assertThat(wrs.size(), is(5));
    final Table<Integer, String, String> expected = db.reference(REFERENCE_SELECT);
    final Table<Integer, String, String> actual = ConvertToTable.fromResultSet(wrs);
    assertThat(actual, is(expected));//from w  ww  .  j  ava2s . c om
}

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));
    final ResultSetMetaData context = wrs.getMetaData();
    for (int index = 0; index < COLUMN_NAMES.length; index++) {
        assertThat(context.getColumnName(index + 1), is(COLUMN_NAMES[index]));
    }//w ww.ja v a 2 s.  co  m
}

From source file:com.oracle.tutorial.jdbc.WebRowSetSample.java

public void testWebRowSet() throws SQLException, IOException {
    FileReader fReader = null;//from www. jav  a  2  s  .c  om
    FileWriter fWriter = null;
    String priceListFileName = "pricelist.xml";
    int[] keyCols = { 1 };
    WebRowSet priceList = new WebRowSetImpl();

    priceList.setUsername(settings.userName);
    priceList.setPassword(settings.password);
    priceList.setUrl(settings.urlString);
    priceList.setCommand("select COF_NAME, PRICE from COFFEES");
    priceList.setKeyColumns(keyCols);

    // Populate the WebRowSet
    priceList.execute();
    System.out.println("Size of the WebRowSet is: " + priceList.size());

    // Insert a new row
    priceList.moveToInsertRow();
    priceList.updateString("COF_NAME", "Kona");
    priceList.updateFloat("PRICE", 8.99f);
    priceList.insertRow();
    priceList.moveToCurrentRow();
    System.out.println("New row inserted");
    System.out.println("Size of the WebRowSet is: " + priceList.size());

    //Delete the row with "Espresso"
    priceList.beforeFirst();
    while (priceList.next()) {
        if (priceList.getString(1).equals("Espresso")) {
            System.out.println("Deleting row with Espresso...");
            priceList.deleteRow();
            break;
        }
    }

    // Update price of Colombian
    priceList.beforeFirst();
    while (priceList.next()) {
        if (priceList.getString(1).equals("Colombian")) {
            System.out.println("Updating row with Colombian...");
            priceList.updateFloat(2, 6.99f);
            priceList.updateRow();
            break;
        }
    }

    int size1 = priceList.size();
    fWriter = new FileWriter(priceListFileName);
    priceList.writeXml(fWriter);
    fWriter.flush();
    fWriter.close();

    // Create the receiving WebRowSet object
    WebRowSet receiver = new WebRowSetImpl();
    receiver.setUrl(settings.urlString);
    receiver.setUsername(settings.userName);
    receiver.setPassword(settings.password);

    //Now read the XML file.
    fReader = new FileReader(priceListFileName);
    receiver.readXml(fReader);
    int size2 = receiver.size();
    if (size1 == size2) {
        System.out.println("WebRowSet serialized and " + "deserialiazed properly");
    } else {
        System.out.println("Error....serializing/deserializng the WebRowSet");
    }
}