public static ResultSet linkSchema(Connection conn, String targetSchema, String driver, String url, String user,
String password, String sourceSchema) {
Connection c2 = null;
Statement stat = null;
ResultSet rs = null;
SimpleResultSet result = new SimpleResultSet();
result.addColumn("TABLE_NAME", Types.VARCHAR, Integer.MAX_VALUE, 0);
try {
c2 = JdbcUtils.getConnection(driver, url, user, password);
stat = conn.createStatement();
stat.execute("CREATE SCHEMA IF NOT EXISTS " + StringUtils.quoteIdentifier(targetSchema));
rs = c2.getMetaData().getTables(null, sourceSchema, null, null);
while (rs.next()) {
String table = rs.getString("TABLE_NAME");
StringBuilder buff = new StringBuilder();
buff.append("DROP TABLE IF EXISTS ").append(StringUtils.quoteIdentifier(targetSchema)).append('.')
.append(StringUtils.quoteIdentifier(table));
stat.execute(buff.toString());
buff = new StringBuilder();
buff.append("CREATE LINKED TABLE ").append(StringUtils.quoteIdentifier(targetSchema)).append('.')
.append(StringUtils.quoteIdentifier(table)).append('(').append(StringUtils.quoteStringSQL(driver))
.append(", ").append(StringUtils.quoteStringSQL(url)).append(", ")
.append(StringUtils.quoteStringSQL(user)).append(", ").append(StringUtils.quoteStringSQL(password))
.append(", ").append(StringUtils.quoteStringSQL(table)).append(')');
stat.execute(buff.toString());
result.addRow(table);
}
} catch (SQLException e) {
throw DbException.convert(e);
} finally {
JdbcUtils.closeSilently(rs);