我已经使用 ddlUtils 成功导出了 Derby 模式,但是如何在 derby 中导出表数据以插入 SQL 语句?
If you're willing to use a third-party tool for this, you could use 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()));
}
}
}
There's a known issue that the above generates the wrong table name in the insert statement. You can fix this by patching the output:
System.out.println(
ctx.fetch(table).formatInsert().replace("UNKNOWN_TABLE", table.getName()));
(Disclaimer: I work for the company behind jOOQ)
Note : I use Netbeans 8.2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.