FileDocCategorySizeDatePackage
CachedRowSetDemo.javaAPI DocExample1308Fri Mar 19 21:15:34 GMT 2004None

CachedRowSetDemo

public class CachedRowSetDemo extends Object
Demonstrate simple use of the CachedRowSet. The RowSet family of interfaces is in JDK1.5, but the Implementation classes are (as of Beta 1) still in the unsupported "com.sun" package.

Fields Summary
public static final String
ROWSET_IMPL_CLASS
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

	       
		CachedRowSet rs;

		// Create the class with class.forName to avoid importing
		// from the unsupported com.sun packages.
		Class c = Class.forName(ROWSET_IMPL_CLASS);
		rs = (CachedRowSet)c.newInstance();

		rs.setUrl("jdbc:postgresql:tmclub");
		rs.setUsername("ian");
		rs.setPassword("secret");

		rs.setCommand("select * from members where name like ?");
		rs.setString(1, "I%");

		// This will cause the RowSet to connect, fetch its data, and
		// disconnect
		rs.execute();

		// Some time later, the client tries to do something.

		// Suppose we want to update data:
		while (rs.next()) {
			if (rs.getInt("id") == 42) {
				rs.setString(1, "Marvin");
				rs.updateRow();	// Normal JDBC

				// This additional call tells the CachedRowSet to connect
				// to its database and send the updated data back.
				rs.acceptChanges();
			}
		}
	
		// If we're all done...
		rs.close();