Welcome

JDBC Tutorial


JDBC Rowsets

      JDBC RowSets RowSets are snapshot of the SQL Query. RowSets are stored in the memory. Which supports Updatable Rows, Scrollable ResultSets. javax.sql package has RowSet Interface. This interface adds support to JavaBeans style Interface for the JDBC API. Some of the RowSets are connection oriented, some of them are disconnected oriented. In Distributed Applications or Multitier Applications where each layer is hosted in different machines, for ex: Web Applications which works in Disconnected Apporach, Rowsets are best suited in Multi-tier Applications.

  • JDBCRowSet— a connected rowset that serves mainly as a thin wrapper around a ResultSet object to make a JDBC driver look like a JavaBeans component.
  • CachedRowSet— a disconnected rowset that caches its data in memory; not suitable for very large data sets, but an ideal way to provide thin Java clients with tabular data.
  • WebRowSet— a disconnected rowset that caches its data in memory in the same manner as a CachedRowSet object. In addition, a WebRowSet object can read and write its data as an XML document. A WebRowSet object makes it easy to use a rowset in the context of Web services.
  • FilteredRowSet— a disconnected rowset that can be set to filter its contents so that it exposes only a subset of its rows. The next method is implemented to skip any rows that are not in a specified range of rows.
  • JoinRowSet— a disconnected rowset that can combine data from different rowsets into one rowset. This can be especially valuable when the data comes from different data sources.

JDBCROWSET Example

      	RowSetFactory factory = RowSetProvider.newFactory();
	JdbcRowSet jdbcRowSet = factory.createJdbcRowSet();
	
	jdbcRowSet.setCommand("SELECT * FROM EMP");
	jdbcRowSet.setUrl("jdbc:oracle:thin:@localhost:1521/XE");
	jdbcRowSet.setUsername("scott");
	jdbcRowSet.setPassword("tiger");
	jdbcRowSet.execute();
	
	while(jdbcRowSet.next()) {
	    System.out.println( 
	    jdbcRowSet.getInt(1)+" "+jdbcRowSet.getString(2)+" "+
	    jdbcRowSet.getFloat("SAL")+" "+jdbcRowSet.getDate("HIREDATE")
	    );
	}

      

ADS