Example usage for javax.sql.rowset RowSetFactory createJdbcRowSet

List of usage examples for javax.sql.rowset RowSetFactory createJdbcRowSet

Introduction

In this page you can find the example usage for javax.sql.rowset RowSetFactory createJdbcRowSet.

Prototype

public JdbcRowSet createJdbcRowSet() throws SQLException;

Source Link

Document

Creates a new instance of a JdbcRowSet.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    String databaseUrl = "jdbc:derby://localhost:1527/contact";
    String username = "user";
    String password = "password";

    RowSetFactory rowSetFactory = null;
    rowSetFactory = RowSetProvider.newFactory("com.sun.rowset.RowSetFactoryImpl", null);
    JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet();

    rowSet.setUrl(databaseUrl);//from   w  ww .jav  a  2 s.co m
    rowSet.setUsername(username);
    rowSet.setPassword(password);
    rowSet.setCommand("SELECT * FROM COLLEAGUES");
    rowSet.execute();

    while (rowSet.next()) {
        System.out.println(rowSet.getInt("ID") + " - " + rowSet.getString("FIRSTNAME"));
    }
}