Java Reference
In-Depth Information
The first thing you will notice is that the entire example centers on the methods of the RowSet . If you
are working with a ResultSet , you will have to create and work with the following objects:
 
java.sql.Connection
 
java.sql.Statement
 
java.sql.ResultSet
When using a RowSet such as the one in Listing 18-1 , set the required properties of the RowSet itself.
Then use the RowSet.execute() method to execute the SQL command. The JdbcRowSet is
implemented as a wrapper around a ResultSet object that makes it possible to use the ResultSet as a
JavaBeans component. Because a JdbcRowSet is a connected RowSet , continually maintaining its
connection to the database using a JDBC driver, it effectively makes the driver a JavaBeans component.
Listing 18-1: Using a RowSet
package JavaDatabaseBible.ch18;
import java.sql.*;
import com.inet.tds.JDBCRowSet;
public class JDBCRowSetExample{
public static void main(String[] argv){
String url = "jdbc:inetdae7:localhost:1433?database=LEDES";
String login = "jod";
String password = "jod";
try {
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 );
//get the driver version
DatabaseMetaData dbmd = rowSet.getConnection().getMetaData();
System.out.println("Driver Name:\t" + dbmd.getDriverName());
System.out.println("Driver Version:\t" + dbmd.getDriverVersion());
//set the sql command
rowSet.setCommand("SELECT ID,FName,LName,EMail FROM CONTACTS");
//execute the command
Search WWH ::




Custom Search