欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

程序员文章站 2022-06-11 08:09:56
...
We’re importing records from a MySql database and entering them into PostgreSql in Java. In the process we’ll be modifying the MySql data a bit, but that’s for another blog post. Today we’re going to show supporting both input and output database providers which enables us to seamlessly hand-off objects from one data source to another.

We have two providers as you see here, a MySql provider as input and PostgreSql as output.

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

In the base provider class, be it MySql or PostgreSql we use a Connections class to retrieve ourInputConnection()or ourOutputConnection().

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

To retrieve the “NixImportConnection” object we rely on the Configuration class which we’ll see next. Here is where we call the Configuration class in NixImportConnection.

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

We’re one step closer to the connection’s properties in the Configuration class where we’ll retrieve the configuration name of the input and output connections from the app’s properties file.

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

The properties file is where we define the connection name, giving us the ability to change it at any time based on environment or development needs.

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

We arrive at our Connections.xml file where the information to populate our Connection Properties formysql.burkey_nixmash andpostgresql.nixmashupdb.

Simultaneous MySql and PostgreSql Data Connections in Java_MySQL

With dual data providers for MySql and PostgreSql we can easily hand-off objects from one source to another with

NixImportMySql db = NixImportMySql.loadProvider();

and

NixImportPostgreSql db = NixImportPostgreSql.loadProvider();