连接到基于文件的德比数据库 [英] connecting to a file-based derby database

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

问题描述

我想使用apache derby处理基于文件的数据库。
我想知道如果有人可以carify如何连接&使用netbeans作为IDE创建此数据库。
我通过derby手册试图想出这一个,但我得到的是嵌入式Derby JDBC数据库连接,我被告知不是一个基于文件的方法,无论如何,连接没有似乎工作。
任何帮助将非常感谢

I want to work with a file-based database using apache derby. I was wondering if anyone can carify how to connect & create this database using netbeans as an IDE. I passed through derby manuals trying to figure this one out, but all i got was "Embedded Derby JDBC Database Connection", which i was told is not a file-based approach, and either way, the connection didn't seem to work. any help would be much appreciated

推荐答案

当您下载NetBeans 7.1.2时, glassfish应用服务器。安装w / glassfish之后,在IDE中,您应该可以选择服务选项卡>展开数据库,您应该看到Java DB。 R.单击Java DB并选择启动服务器。然后再次单击并选择创建数据库。输入数据库名称,用户和密码。 BTW我通常使用APP的用户和密码,因为这样它也成为默认架构,我不必去改变任何生产环境。

When you download NetBeans 7.1.2, the "All" package you get the glassfish app server with it. After installing w/ glassfish, in the IDE you should be able to select the Services tab > Expand Databases and you should see Java DB. R. Click on Java DB and select Start Server. Then R. Click again and select Create Database. Enter the db name, user and a password. BTW i normally use APP for both the user and password because this way it also becomes the default schema and I don't have to go changing around anything for production environment.

现在,在Java数据库组中,您应该看到创建的新数据库。点击它,然后选择连接。您应该会在数据库组下看到连接项。展开此项目,您应该看到APP模式以粗体显示,表示它是默认模式。展开那个和R.单击表选择创建表,你会得到一个帮助你填充表。重复,直到创建所有表。使用ide创建表的其他方法是右键单击Tables并选择Execute Command,您可以在其中运行DDL以定义表模式。这是我做数据库创建的方式,通过将我的脚本保存为.sql文件,所以我可以删除数据库,并重新运行它需要的。

Now in the Java DB group you should see the new database you created. R. Click on that and select connect. You should see a connection item appear under the Databases group. Expand this item and you should see the APP schema in bold indicating it is the default schema. Expand that and R. Click on the Tables select Create Table and you'll get a ui that helps you populate a table. Repeat until all your tables are created. Other ways to create tables using the ide is right click on the Tables and select Execute Command where you can run DDL to define the tables schema. This is the way i do db creation, by saving my script as an .sql file so i can delete the db and rerun it again as needed.

这里是一个例子我的dbinit.sql脚本用于在derby中创建我的表。

Here is an example of the my dbinit.sql script i use to create my tables in derby.

create table usertable (
    username varchar(128) NOT NULL CONSTRAINT USER_PK PRIMARY KEY ,
    password varchar(128) NOT NULL,
    email varchar(128) NOT NULL,
    firstname varchar(128) NOT NULL,
    lastname varchar(128) NOT NULL
);

create table grouptable(
    username varchar(128) NOT NULL,
    groupid  varchar(128) NOT NULL,
    CONSTRAINT GROUP_PK PRIMARY KEY(username, groupid),
    CONSTRAINT USER_FK FOREIGN KEY(username) REFERENCES usertable(username)
        ON DELETE CASCADE ON UPDATE RESTRICT
);

insert into usertable(username,password,firstname,lastname) 
    values ('admin', '21232f297a57a5a743894a0e4a801fc3','','');
insert into grouptable(username,groupid) values ('admin', 'USER');
insert into grouptable(username,groupid) values ('admin', 'ADMIN');

您可以通过右键单击数据库轻松删除您创建的数据库,R。要删除的数据库并选择删除。并重新使用您的脚本重新生成它。

You can easily delete the database you've created by right clicking on the database, R. click on the database you wish to remove and select delete. and reuse your script to regenerate it.

希望这有助于! :)

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

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