Java Reference
In-Depth Information
Class.forName("com.inet.tds.TdsDriver").newInstance();
JDBCRowSet rowSet = new JDBCRowSet();
//set url,login and password;
rowSet.setUrl( url );
rowSet.setUsername( login );
rowSet.setPassword( password );
//make the rowset scrollable
rowSet.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
//set the sql command
rowSet.setCommand("SELECT ID,FName,LName,EMail FROM CONTACTS");
//execute the command
rowSet.execute();
// read the data and put it to the console
while (rowSet.next()){
for(int j=1; j<=rowSet.getMetaData().getColumnCount(); j++){
System.out.print( rowSet.getObject(j)+"\t");
}
System.out.println();
}
while (rowSet.previous()){
for(int j=1; j<=rowSet.getMetaData().getColumnCount(); j++){
System.out.print( rowSet.getObject(j)+"\t");
}
System.out.println();
}
rowSet.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
The output of the example in Listing 18-2 is the same as the output of Listing 18-1 , except that the
results are printed again in reverse order using the RowSet.previous() method to step backwards
through the rows. You can use the other cursor-control and scrolling methods inherited from the
ResultSet in exactly the same way.
In much the same way, you can very easily make a RowSet updatable. An updatable RowSet allows
you to make updates to the values in the RowSet itself. These changes are reflected in the database
Search WWH ::




Custom Search