Joining tables from multiple sources in Java

Viewed 76

I'm trying to join data from a postgres database with data from a legacy application's SQL Server database in Java. This is required in many cases for my project.

These instances are on seperate servers.

I've attempted to query each datasource using JDBC populate a CachedRowSet and add both cached row sets to a javax.sql.rowset.JoinRowSet.

This seems to work fine with multiple queries to the same datasource but I'm getting a NullPointerException on adding the legacy DataSet.

Exception in thread "main" java.sql.SQLException: Genric joinrowset intial error java.lang.NullPointerException
  at java.sql.rowset/com.sun.rowset.JoinRowSetImpl.initJOIN(JoinRowSetImpl.java:860)
  at java.sql.rowset/com.sun.rowset.JoinRowSetImpl.addRowSet(JoinRowSetImpl.java:255)
  at java.sql.rowset/com.sun.rowset.JoinRowSetImpl.addRowSet(JoinRowSetImpl.java:312)

Here's my approach to reach this.

RowSetFactory factory = RowSetProvider.newFactory();

ResultSet resultSet1 = connection1.createStatement().executeQuery(SQL1);
CachedRowSet cachedRowSet1 = factory.createCachedRowSet();
cachedRowSet1.populate(resultSet1);

ResultSet resultSet2 = connection2.createStatement().executeQuery(SQL2);
CachedRowSet cachedRowSet2 = factory.createCachedRowSet();
cachedRowSet2.populate(resultSet2);

JoinRowSet joinRowSet = factory.createJoinRowSet();

joinRowSet.addRowSet(cachedRowSet1, ID);
joinRowSet.addRowSet(cachedRowSet2, ID);

Thanks

0 Answers
Related