Apache Derby手记

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值