Example usage for javax.sql.rowset JoinRowSet getString

List of usage examples for javax.sql.rowset JoinRowSet getString

Introduction

In this page you can find the example usage for javax.sql.rowset JoinRowSet getString.

Prototype

String getString(int columnIndex) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.

Usage

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

public void testJoinRowSet(String supplierName) throws SQLException {

    CachedRowSet coffees = null;/* w  w  w. j  a v  a 2s .co  m*/
    CachedRowSet suppliers = null;
    JoinRowSet jrs = null;

    try {
        coffees = new CachedRowSetImpl();
        coffees.setCommand("SELECT * FROM COFFEES");
        coffees.setUsername(settings.userName);
        coffees.setPassword(settings.password);
        coffees.setUrl(settings.urlString);
        coffees.execute();

        suppliers = new CachedRowSetImpl();
        suppliers.setCommand("SELECT * FROM SUPPLIERS");
        suppliers.setUsername(settings.userName);
        suppliers.setPassword(settings.password);
        suppliers.setUrl(settings.urlString);
        suppliers.execute();

        jrs = new JoinRowSetImpl();
        jrs.addRowSet(coffees, "SUP_ID");
        jrs.addRowSet(suppliers, "SUP_ID");

        System.out.println("Coffees bought from " + supplierName + ": ");
        while (jrs.next()) {
            if (jrs.getString("SUP_NAME").equals(supplierName)) {
                String coffeeName = jrs.getString(1);
                System.out.println("     " + coffeeName);
            }
        }
    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (jrs != null) {
            jrs.close();
        }
        if (suppliers != null) {
            suppliers.close();
        }
        if (coffees != null) {
            coffees.close();
        }
    }
}