Java Reference
In-Depth Information
Use a JoinRowSet to take data from two relational database tables and join them.
The data from each table that will be joined should be fetched into a RowSet and then
the JoinRowSet can be used to join each of those RowSet objects based on related
elements contained within them. For instance, suppose that there were two related
tables within a database. One of the tables stores a list of authors, and the other table
contains a list of chapters that are written by those authors. The two tables can be
joined using SQL by the primary and foreign key relationship.
Note A primary key is a unique identifier within each record of a database table, and
a foreign key is a referential constraint between two tables.
However, the application will not be connected to the database to make the JOIN
query, so it must be done using a JoinRowSet . The following class listing demon-
strates one strategy that can be used in this scenario:
package org.java8recipes.chapter13.recipe13_11;
import com.sun.rowset.JoinRowSetImpl;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.JoinRowSet;
import javax.sql.rowset.RowSetFactory;
import javax.sql.rowset.RowSetProvider;
import
org.java8recipes.chapter13.recipe13_01.CreateConnection;
public class JoinRowSetExample {
public static Connection conn = null;
public static CreateConnection createConn;
public static CachedRowSet bookAuthors = null;
public static CachedRowSet authorWork = null;
public static JoinRowSet jrs = null;
public static void main(String[] args) {
boolean successFlag = false;
Search WWH ::




Custom Search