Java Reference
In-Depth Information
}
public CachedRowSetSerializer(){
}
public void serializeRows(){
String url = "jdbc:odbc:LEDES";
String login = "jod";
String password = "jod";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
CachedRowSet rowSet = new CachedRowSet();
//set url,login and password;
rowSet.setUrl( url );
rowSet.setUsername( login );
rowSet.setPassword( password );
//make the rowset scrollable and updatable
rowSet.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE);
//set the sql command
rowSet.setCommand("GET_CONTACT_LIST");
//execute the command
rowSet.execute();
FileOutputStream fOut = new FileOutputStream(fName);
ObjectOutput out = new ObjectOutputStream(fOut);
out.writeObject(rowSet);
out.flush();
out.close();
//close the RowSet
rowSet.close();
}catch(Exception e) {
System.err.println(e.getMessage());
}
}
}
Client-side code
The code at the client side is even simpler. The serialized CachedRowSet bean is deserialized, and the
RowSets are output to the console, as shown in Listing 18-8 . A practical application would probably use
the CachedRowSet bean as a component driving a simple GUI.
Search WWH ::




Custom Search