简体   繁体   English

如何从Netbeans,Java DB(Derby)数据库导出表

[英]How to export table from Netbeans, Java DB (Derby) Database

I need to export the structure of some tables so I can easily recreate them on a different database. 我需要导出一些表的结构,以便可以在其他数据库上轻松地重新创建它们。 I tried to use the Grab Structure but this seems to work only if I try to create a new table within Netbeans. 我尝试使用Grab Structure,但是只有当我尝试在Netbeans中创建新表时,这似乎才起作用。 Any ideas on how to do this? 有关如何执行此操作的任何想法?

Export a table structure 导出表结构

In Netbeans 在Netbeans中

right click a table to export -> Grab Structure 右键单击表以导出-> Grab Structure

在此处输入图片说明

Save the file 保存文件

在此处输入图片说明

  • right click a table to recreate -> Recreate Table 右键单击表以重新创建-> Recreate Table
  • open the file just created 打开刚创建的文件
  • choose Edit table script 选择Edit table script

在此处输入图片说明

  • do a Ctrl-a and Ctrl-c . 执行Ctrl-a和Ctrl-c。 To mark all and copy to clipboard. 标记全部并复制到剪贴板。
  • close with cancel . 关闭cancel

在此处输入图片说明

Important close Netbeans to close all connections ( a disconnect inside Netbeans is not enough) 重要关闭Netbeans以关闭所有连接(Netbeans内部的断开连接是不够的)

Go to your Databases folder 转到您的数据库文件夹

在此处输入图片说明

inside this folder call your ij 在此文件夹中调用您的ij
otherwise the database can not be found. 否则找不到数据库

在此处输入图片说明

connect and select look if the right database is opened. connectselect查看是否打开了正确的数据库。

  • connect 'jdbc:derby:sample;user=app;password=app'; 连接'jdbc:derby:sample; user = app; password = app';
  • select * from FRIENDS; 从朋友中选择*;

在此处输入图片说明

  • open Notepad and paste the structure from the clipboard. 打开记事本,然后从剪贴板粘贴该结构。
  • for later use save it to file. 供以后使用,将其保存到文件中。
  • here I renamed FRIENDS to MYFRIENDS to not overwright my Friends table. 在这里,我将FRIENDS重命名为MYFRIENDS ,以免覆盖我的Friends表。
  • Select all and copy again. 全选并再次复制。
  • paste to ij and hit enter 粘贴到ij并按enter
  • do a select to test if table MYFRIENDS is created. 选择要测试的表MYFRIENDS是否已创建。

在此处输入图片说明

Now we close ij with quit; 现在我们以quit;关闭ij quit; to test in Netbeans we open Netbeans again. 为了在Netbeans中进行测试,我们再次打开Netbeans。
And here it is. 在这里。 everything in the right position with the right properties. 具有正确属性的所有位置都正确。

在此处输入图片说明

Try using Apache DDLUtils: http://db.apache.org/ddlutils/ . 尝试使用Apache DDLUtils: http ://db.apache.org/ddlutils/。 It can export and import schema from many database implementations (this text added to exceed the minimum answer limit). 它可以从许多数据库实现中导出和导入模式(添加的文本超出了最小答案限制)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM