So I’m trying to run a code which creates a table in a remote MySQL server, by referencing tables located in a different MYSQL server. The server that I am trying to create a table in has space limitations, and the tables that are being referenced are very large, so they have to be kept on a different remote server.
I’m trying to find a way to set up persistent connections to both databases at the same time (using JDBC libraries) so I don’t have to keep buffering small numbers of lines of data… I’d like to be able to just reference the data directly.
E.g.
Database A contains the data I am referencing, and Database B is where I am creating the new tables.
say the table I am referencing in Database A is 1,000,000 lines. Instead of, say, opening a connection to Database A, buffering 10,000 lines, closing the connection, opening a connection to Database B, writing the that database, deleting my buffer, and repeating…
I’d like to just have a persistent connection to database A, so every write to Database B can reference the data in Database A.
Is this possible? I’ve tried several ways (mostly by creating new connection objects that only refresh if the connection breaks), and I can’t seem to get this idea working.
Has anyone done something similar to this using JDBC? If so, It would be much appreciated if you could point me in the right direction, or tell me how you managed to get it working.
You could create the data in Database A, and copy it to Database B via replication.
Alternatively, it sounds like you’re implementing a queue of some kind. I once built a data-copying program in Java, which used a built-in implementation of the Queue interface. I had a thread that read the data from Database A and filled the queue, and a thread that read from the queue and wrote to Database B. I can try and dig up the classes I used if that’s any use?
EDIT:
Here’s the code, somewhat tweaked for publishing. I haven’t include the config classes, but it should give you the idea of how to use the queue class;