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

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

问题描述

我想使用 apache derby 处理基于文件的数据库.我想知道是否有人可以解释如何连接 &使用 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 时,All"包将包含 glassfish 应用服务器.安装了 glassfish 后,在 IDE 中,您应该能够选择服务"选项卡 >展开数据库",您应该会看到 Java DB.R. 单击 Java DB 并选择启动服务器.然后 R.再次单击并选择创建数据库.输入数据库名称、用户和密码.顺便说一句,我通常将 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 DB 组中,您应该会看到您创建的新数据库.R. 单击它并选择连接.您应该会看到一个连接项出现在 Databases 组下.展开此项,您应该会看到以粗体显示的 APP 架构,表明它是默认架构.展开它和 R.单击 Tables 选择 Create Table,您将获得一个可帮助您填充表格的 ui.重复直到创建所有表.使用 ide 创建表的其他方法是右键单击表"并选择执行命令",您可以在其中运行 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.

这是我用来在 derby 中创建表的 dbinit.sql 脚本的示例.

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.

希望这有帮助!:)

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

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