This is just an example how you could do this. Remeber that ?
mark is one parameter/value to pass. So you need to modify your query for your purpose.
I have no idea what type of columns your table has so modify this if you need.
//Representation of single item in table
class DbTableItem {
private String value1;
private String value2;
private String value3;
//... Whatever field that required to exchange information between 2 tables
public String getValue1() {
return value1;
}
public void setValue1(String value1) {
this.value1 = value1;
}
public String getValue2() {
return value2;
}
public void setValue2(String value2) {
this.value2 = value2;
}
public String getValue3() {
return value3;
}
public void setValue3(String value3) {
this.value3 = value3;
}
}
Connection connection1 =//your connection to local db;
Connection connection2 =//your connection to another db;
PreparedStatement stmA = connection.prepareStatement("SELECT * FROM dbTable");
//Executing query to retreive data
ResultSet resultSet = stmA.executeQuery();
List<DbTableItem> dbTableList = new ArrayList<>();
//Setting items and adding to list
while (resultSet.next()){
DbTableItem dbTableItem = new DbTableItem();
dbTableItem.setValue1(resultSet.getString("COLUMN_NAME"));
dbTableItem.setValue2(resultSet.getString("COLUMN_NAME"));
dbTableItem.setValue2(resultSet.getString("COLUMN_NAME"));
dbTableList.add(dbTableItem);
}
//Preparing next query for batch process
PreparedStatement stmB = connection2.prepareStatement("INSERT INTO codes VALUES (?,?,?)");
//Adding to batch
for(DbTableItem dbTableItem: dbTableList) {
stmB.setObject(1, dbTableItem.getValue1());
stmB.setObject(2, dbTableItem.getValue2());
stmB.setObject(2, dbTableItem.getValue3());
//And so on
stmB.addBatch();
}
//Executing batch with query
stmB.executeBatch();
//Droping table
//Closing connection1 and connection2