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.


你可能感兴趣的:(apache,sql,jdbc,SQL Server,Derby)