六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 206|回复: 0

Apache Derby手记

[复制链接]

升级  40%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
20
 楼主| 发表于 2013-1-14 23:04:47 | 显示全部楼层 |阅读模式
Apache Derby手记
遗憾没有管理员账号,不能够安装MySQL。更不要说那些Oracle,DB2,SQL Server那些巨无霸了。
偶然找到了Derby,绿色的,符合JDBC标准的纯Java的数据库,体积细小,移植性好,不用安装,挺爽的。

1 下载:
1.1 http://db.apache.org/derby/
1.2 解压
2 安装
2.1配置DERBY_HOME环境变量
2.2配置相关的Path和ClassPath
3 运行(三种方式)
3.1命令行 java -jar %DERBY_HOME%\lib\derbyrun.jar ij [-p propertiesfile] [sql_script]
ij.bat是一个jdbc连接的工具
基本语法:
CONNECT 'jdbc:derby:firstdb;create=true';
CREATE TABLE FIRSTTABLE (ID INT PRIMARY KEY, NAME VARCHAR 12));
INSERT INTO FIRSTTABLE VALUES (10,'TEN'),(20,'TWENTY'),(30,'THIRTY');
SELECT * FROM FIRSTTABLE;
run 'ToursDB_schema.sql';
exit;



3.2自带脚本
3.3开发程序运行

4 JDBC连接数据库
4.1内嵌Jdbc驱动:程序中添加derby.jar
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String dbName = "jdbcDemoDB";
String connectionURL = "jdbc:derby:" + dbName + ";create=true";
Class.forName(driver);
4.2 client driver and Network Server 使用c/s架构的derby驱动连接
项目添加derbyclient.jar
运行服务器java -jar %DERBY_HOME%\lib\derbyrun.jar server start
String driver = "org.apache.derby.jdbc.ClientDriver";

String dbName = "jdbcDemoDB";

String connectionURL = "jdbc:derby://localhost:1527/" + dbName + ;create=true";
5 JDBC URL
jdbc:derby://server[:port]/databaseName[;URLAttributes=value[;...]]

6主要脚本
bin/dblook
    Runs the dblook tool.
bin/ij
    Starts the ij tool.
bin/NetworkServerControl
    Runs NetworkServerControl.
bin/setEmbeddedCP
    Puts all of the Derby libraries for an embedded environment in the CLASSPATH.
bin/setNetworkClientCP
    Puts the libraries needed to connect to the Derby Network Server into the CLASSPATH.
bin/setNetworkServerCP
    Puts the libraries needed to start the Derby Network Server into the CLASSPATH.
bin/startNetworkServer
    Starts the Network Server on the local machine.
bin/stopNetworkServer
    Stops the Network Server on the local machine.
bin/sysinfo
    Runs the sysinfo tool.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表