Multi-Database Applications
So far we’ve discussed simple local database access from Java using JDBC, and various approaches for connecting Java agents to remote databases. Some simple extensions to these approaches allow you to connect a Java agent to multiple remote databases, and create some interesting possibilities for applications in data analysis and management.
A feature of JDBC that should be obvious from earlier sections is
that it insulates the application from the proprietary details of the
database. So assuming that we’ve encapsulated the data-access
tier of our application well, and that we have local JDBC drivers
that can access each database server, we can easily distribute our
data across multiple database servers and still pull the data
together into a single set of data objects simply by using multiple
Connection objects.
As an example, suppose that the tables shown in Figure 7.3 are stored in two separate databases: all
tasks and time constraints on tasks are stored in a database named
“sequence” on server “data1,” while resource
and resource assignment data is stored in a database named
“schedule” on server “data2.” Our
JDBC-enabled data objects now simply need access to
Connections to each of these databases, assuming
that the tables in the separate databases are defined the same way
they were in the single database. We can modify our
DatabaseItem
class to contain two
Connection objects, as shown in Example 7.13.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access