derby简介
1. 安装
首页
http://db.apache.org/derby/index.html
下载
http://db.apache.org/derby/derby_downloads.html
文件
db-derby-10.4.2.0-bin.zip
The Apache Derby plug-ins for Eclipse provide a seamless integration between Eclipse and Apache Derby
seamless [ 'si:mlis ] 无缝的
eclipse插件
http://db.apache.org/derby/releases/release-10.4.2.0.cgi
derby_core_plugin - provides the Derby jar files to other plugins in Eclipse.
derby_ui_plugin - provides an Apache Derby Nature in Eclipse for easy database application development.
插件文件
derby_ui_plugin_1.1.2.zip
derby_core_plugin_10.4.2.zip
解开压缩包,将plugins目录下面的所有文件拷贝到eclipse下面的plugins下面
重启eclipse,选中某项目 右键-----》Apache Derby -----》 Add Apache Derby nature
2.启动Derby Server
With the Java project selected, bring up the context menu and select the menu item, Apache Derby, Start Derby Network Server
The pop-up box will appear which states the Apache Derby Network Server is attempting to be started
默认启动是按照默认参数,端口为1527
修改启动参数
With the Java project active in the Package Explorer or Navigator view, select the menu item Project, Properties
3.启动工具ij
Select the project and bring up the context menu. Select the menu item, Apache Derby, ij (Interactive SQL).
The first step to using Derby is to connect to the database using a database JDBC connection URL.
The database connection URL we'll use for this example will connect to our Network Server using the Derby Network Client driver on the localhost. We'll create a database called myDB as the user 'me' with a password of 'mine.'
To connect to the database from ij we need to issue the connect command, so the entire command to connect to our database looks like this:
connect 'jdbc:derby://localhost:1527/myDB;create=true;user=me;password=mine';
connect 'jdbc:derby://localhost:1527/springside-example;create=true;user=APP;password=APP';
Cut and paste the above connection URL into the ij console window. It should create a database in the current workspace, under the current Java project, called myDB.
参考mini-web的derby例子
可以写一个建表的SQL文件schema.sql如下:
connect 'jdbc:derby://localhost:1527/springside-example;create=true;user=APP;password=APP';
drop table ROLES_AUTHORITIES;
drop table USERS_ROLES;
drop table USERS;
drop table ROLES;
drop table AUTHORITIES;
create table USERS (
ID integer primary key GENERATED ALWAYS AS IDENTITY,
LOGIN_NAME varchar(20) not null unique,
PASSWORD varchar(20),
NAME varchar(20),
EMAIL varchar(30)
);
create table ROLES (
ID integer primary key GENERATED ALWAYS AS IDENTITY,
NAME varchar(20) not null unique
);
create table USERS_ROLES (
USER_ID integer not null,
ROLE_ID integer not null,
FOREIGN KEY (ROLE_ID) references ROLES(ID),
FOREIGN KEY (USER_ID) references USERS(ID)
);
CREATE TABLE AUTHORITIES (
ID integer primary key GENERATED ALWAYS AS IDENTITY,
NAME varchar(20) not null,
DISPLAY_NAME varchar(20) not null
);
create table ROLES_AUTHORITIES (
ROLE_ID integer not null,
AUTHORITY_ID integer not null,
FOREIGN KEY (ROLE_ID) references ROLES(ID),
FOREIGN KEY (AUTHORITY_ID) references AUTHORITIES(ID)
);
disconnect;
exit;
一个导入数据的SQL文件如下load-data.sql如下:
connect 'jdbc:derby://localhost:1527/springside-example;create=true;user=APP;password=APP';
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('admin','admin','Admin','admin@springside.org.cn');
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('user','user','User','user@springside.org.cn');
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('user2','user2','Jack','jack@springside.org.cn');
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('user3','user3','Kate','kate@springside.org.cn');
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('user4','user4','Sawyer','sawyer@springside.org.cn');
insert into USERS (LOGIN_NAME,PASSWORD,NAME,EMAIL) values('user5','user5','Ben','ben@springside.org.cn');
insert into ROLES (NAME) values('管u29702 员);
insert into ROLES (NAME) values('用u25143 ');
insert into AUTHORITIES (NAME,DISPLAY_NAME) values('ROLE_VIEW_USER','查u30475 用u25143 ');
insert into AUTHORITIES (NAME,DISPLAY_NAME) values('ROLE_MODIFY_USER','管u29702 用u25143 ');
insert into AUTHORITIES (NAME,DISPLAY_NAME) values('ROLE_VIEW_ROLE','查u30475 角u-32142 ');
insert into AUTHORITIES (NAME,DISPLAY_NAME) values('ROLE_MODIFY_ROLE','管u29702 角u-32142 ');
insert into USERS_ROLES values(1,1);
insert into USERS_ROLES values(1,2);
insert into USERS_ROLES values(2,2);
insert into USERS_ROLES values(3,2);
insert into USERS_ROLES values(4,2);
insert into USERS_ROLES values(5,2);
insert into USERS_ROLES values(6,2);
insert into ROLES_AUTHORITIES values(1,1);
insert into ROLES_AUTHORITIES values(1,2);
insert into ROLES_AUTHORITIES values(1,3);
insert into ROLES_AUTHORITIES values(1,4);
insert into ROLES_AUTHORITIES values(2,1);
insert into ROLES_AUTHORITIES values(2,3);
disconnect;
exit;
执行SQL的时候如下操作
The last step is to run the SQL script. Right-click the restaurants.sql file in the Package Explorer view and select Apache Derby, Run SQL Script using 'ij'.
出现一个问题,执行出来到derby的数据是乱码
修改eclipse配置打开"windows->preferences->general->workspace",把text file encoding从GBK改回UTF-8就行了
分享到:
相关推荐
使用mysql,sql等数据库,当你的程序出现在一个没有安装数据库的电脑,该程序无法使用数据库,但是derby是内置在项目中的数据,体积小,免安装,可以达到你想要的java数据库程序不需要配置在任何机器上运行
java编写的数据库derby
真正的Derby新手教程,Derby安装,创建数据库,在Java程序中使用Derby 本人原创
Apache Derby是一个完全用java编写的数据库,Derby是一个Open source的产品,基于Apache License 2.0分发。 Apache Derby非常小巧,核心部分derby.jar只有2M,所以既可以做为单独的数据库服务器使用,也可以内嵌在...
Derby数据库连接方法是Java应用程序连接Derby数据库的主要方式。 Derby数据库是一种嵌入式关系数据库管理系统,可以嵌入到Java应用程序中,提供了一个轻量级、可靠的数据库解决方案。 连接Derby数据库方法 1. 使用...
JAVA编写的适合家庭用的图书管理系统(derby数据库),JAVA数据库课设,压缩包里有使用说明,都是自己写的,不分享一下可惜了
本文档详解了java6中derby内建的Derby数据库的使用及两种不同应用下解决方案。
Java Diary - JDK自带的java数据库,并且是完全的关系型书库据----Derby
详细描述了derby的使用,Derby数据库是一个纯用Java实现的内存数据库,属于Apache的一个开源项目。由于是用Java实现的,所以可以在任何平台上运行;另外一个特点是体积小,免安装,只需要几个小jar包就可以运行了。
(百科)Apache Derby是一个完全用java编写的数据库,Derby是一个Open source的产品,基于Apache License 2.0分发。 Apache Derby非常小巧,核心部分derby.jar只有2M,所以既可以做为单独的数据库服务器使用,也...
试过了,可以用的。这次没有出现 数据库连接错误的问题
简单的商品出入库操作的例子,还有打印的小功能,应用了derby数据库,这样可以将数据库也打包成一个exe文件,可以不用客户端安装数据库了。
将目光放在小 Derby 的原因是纯绿色、轻巧、内存占用小,分分钟在你机子跑起来,自己做点需要连接数据库的代码实践非常方便。 虽然 Mysql 也可以,多一种选择,不是也挺好么? Apache Derby是一个完全用 ...
derby的入门资料 给大家共享过来 很值得下载
嵌入式数据库Apache Derby是用 Java 语言编写的,所以可以在任何存在合适的 Java 虚拟机(JVM)的地方运行,Derby软件绑定在Java档案(JAR)文件中,只有2MB大小.
感觉:因为derby是纯Java的数据库,因此与应用可以无缝连接,它支持中文、图片的存贮与读取等。是一个非常好客户端数据库。该数据数应该为J2ME编程带来非常大的好处,同时也为J2SE和J2EE编程来带方便。
Java6中自带的JavaDB(derby)数据库.pdf