数据库迁移 [英] Database Migration

查看:126
本文介绍了数据库迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用java中的数据库迁移工具。该工具将其数据的数据库表复制到目标数据库。但我想要在不同的数据库上工作。从mysql复制并在derby中创建等。通过JDBC,我们可以收集有关表及其列的足够信息。但我会问这个,如果我可以重新创建表与java的sql免费。我的意思是不同的数据库有不同的数据类型,有时他们不同的sql语法。因此,可以使用JDBC或任何其他库(可以是开源的)以一种简单和全球的方式完成这项工作?

I am working on database migration tool in java. The tool is copying database tables with their data's to the destination database. But i want it to work on different databases. Copy from mysql and create in derby etc. With JDBC, we can gather enough information about the table and its columns. But i am going to ask this, if i can recreate tables on java with sql free. I mean different databases have different data types and some times they differs at sql syntax. So can JDBC or any other library (can be open source) do this job at an easy and global way?

PS:第一个问题,但是我第一次提交网站,所以大家好。

PS: First question in SO, i have been reading posts but first time I am contributing the site, so hello everybody.

推荐答案

Apache的 DdlUtils 完成我需要的。当我搜索crossdb发现它,它是非常有用,但强大。它可以从头开始生成数据库,只需使用参数即可。或者它可以抓取现有的数据库表定义,也可以使用索引定义。你可以使用分隔符,如果你想要的(这是一个致命的重要选项,我使用Apache Derby)。你可以打印出这些定义或直接应用到源数据库(我还没有尝试第二个)。它翻译选定数据库的定义。但一个大问题是没有关于如何开始使用它的好教程。我通过包搜索找到一个好地方开始。这里是我已经实现的,一个示例代码生成完整的数据库表创建sql。

Apache's DdlUtils is done what i need. When I am searching about crossdb found it, and it is very useful yet powerful. It can generate a database from scratch, just with the parameters. Or it can grab existing database table definitions, also with index definitions. You can use delimiter if you want (it is a deadly important option for me to use Apache Derby). You can just print out these definitions or apply them directly to source database (i havent tried the second one yet). It translates definitions for the selected database. But one big problem is there is no good tutorial about how to start using it. I searched through the packages to find a good place to start. Here is what i have achieved, a sample code to generate full database table create sql.

DerbyPlatform dp = new DerbyPlatform();
dp.setDelimitedIdentifierModeOn(true);
Database dbs = new Database();
DerbyModelReader dmr = new DerbyModelReader(dp);
Database test = dmr.getDatabase(conn, "MyDBTest");

DerbyBuilder db = new DerbyBuilder(dp);
String testSqlDerby = dp.getCreateTablesSql(test, true, true);
System.out.println(testSqlDerby);

System.out.println("\n\n\n\n");

MySql50Platform mp = new MySql50Platform();
mp.setDelimitedIdentifierModeOn(true);
MySqlBuilder mb = new MySqlBuilder(mp);
String testSqlMysql = mp.getCreateTablesSql(test, true, true);
System.out.println(testSqlMysql);

这篇关于数据库迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆