ddlUtils を使用して Derby スキーマを正常にエクスポートしましたが、SQL ステートメントを挿入するために Derby でテーブル データをエクスポートするにはどうすればよいですか?
2 に答える
1
これにサードパーティのツールを使用する場合は、 jOOQを使用できます
public class ExportAsInsert {
public static void main(String[] args) {
try (DSLContext ctx = DSL.using(url, user, password)) {
ctx.meta()
.getSchemas()
.stream()
// Filter out those schemas that you want to export
.filter(schema -> schema.getName().equals("TEST"))
// Get the tables for each schema...
.flatMap(schema -> schema.getTables().stream())
// ... and format their content as INSERT statements.
.forEach(table -> System.out.println(ctx.fetch(table).formatInsert()));
}
}
}
上記の INSERT ステートメントで誤ったテーブル名が生成されるという既知の問題があります。これは、出力にパッチを適用することで修正できます。
System.out.println(
ctx.fetch(table).formatInsert().replace("UNKNOWN_TABLE", table.getName()));
(免責事項:私はjOOQの背後にある会社で働いています)
于 2015-11-12T09:11:18.807 に答える