I want to read and write database tables via JDBC without having to tell my Java code anything about the tables except their names.
The only processing that I need to do with the data is comparison and read/write. See below for details.
I'm essentially looking for something like:
A = connect_db();
B = connect_db();
while (row = read_next_row(A)) {
if (A.something == whatever) {
insert_row(B, row);
}
}
In something like PHP that would be easy, I'd read a row into an associative array, done. In Java, this seems overly complex, but I'm not good in Java so I might be missing an obvious, easy solution.
This is all for a low-level, database-first tool that is comparing and copying data between multiple databases. I can assume that the tables are identical among the DBs, with the exception of data types (one DB might call it String and the other Varchar) and additional (internal calculation) columns in some sources that I can safely ignore. The reason I'm looking for a coding solution is that the database systems are different (but all have JDBC connectors).
However, my users are able to change the database structure, so my tool needs to be independent of the column names and types, except for a few columns like a primary ID which is always guaranteed to exist. But, for example, the table about people contains first and last names (and other things) and I cannot guarantee that it won't in the future contain a middle name column. I'd like to not have to change the very simply copy tool for every DB structure change.
What am I missing? Is this possible in Java/JDBC?