derby mysql 同步_Derby 数据库的配置与连接

用了 Derby 数据库好一段时间了,雁过留痕。

作为内存数据库或嵌入式数据库,Derby 是一个很好的选择,完全由 Java 实现,在 JDK1.6 中 Derby 已经作为其一部分来发布了,称之为 JavaDB。

Derby 数据库通过 derby.properties 文件来配置,这个文件需要放在程序的 classpath 或者 jdk 的 javadb classpath 路径中。下面是一些配置的例子:

---------------------------- Derby derby.properties information ----------------------------

--### Derby System Home Directory

derby.system.home=D:/workspace/Boulevard/BoulevardDB

--### Derby Authentication Configuration and Turn On

derby.connection.requireAuthentication=true

derby.authentication.provider=BUILTIN

derby.database.propertiesOnly=true

--### User/Password Definition (System Level)

derby.user.alfred=alfred

--### User Authorization Definition (System Level)

derby.database.defaultAccessMode=fullAccess

derby.fullAccessUsers=cube

--### Some Others Configuration

derby.infolog.append=true

derby.storage.pageSize=4096

derby.storage.pageReservedSpace=60

derby.locks.deadlockTimeout=20

derby.locks.waitTimeout=30

---------------------------- Derby derby.properties information ----------------------------

Derby 数据库可以启动为两种不同的模式:嵌入式模式 或 服务器模式

1. 嵌入式模式(embedded):当 Java 应用程序第一次尝试连接数据库时启动数据库实例,当程序进程结束时数据库实例也被关闭。当数据库实例启动后,仅仅启动它的进程可以访问,其它任何外部进程(运行在当前进程的JVM之外的程序)都不能访问。

下面的命令用于启动并连接一个嵌入式数据库实例:

------------------------------- Derby connection information -------------------------------

-- ### Use ij command to connect embeded database; if not exist, create it.

CONNECT 'jdbc:derby:data;create=true;user=alfred;password=alfred' AS CUBE;

-- ### Use ij command to connect embeded database; if not exist, don't create it, throw out error.

CONNECT 'jdbc:derby:data;user=alfred;password=alfred' AS CUBE;

------------------------------- Derby connection information -------------------------------

2. 服务器模式(network server):数据库实例只能由命令行启动:"...\javadb\bin\startNetworkServer.bat",该实例始终有效,直到通过命令行停止:"...\javadb\bin\stopNetworkServer.bat"。任何运行在本地或远程的JVM进程都可以访问,不会随着访问它的程序的结束而关闭。

下面的命令用于连接(不能启动)服务器数据库实例:

------------------------------- Derby connection information -------------------------------

-- ### Use ij command to connect network server database, reading default repository;

-- ### If not exist, create it.

CONNECT 'jdbc:derby://localhost:1527/data;create=true;user=alfred;password=alfred' AS BOULEVARD;

-- ### Use ij command to connect network server database; reading default repository;

-- ### If not exist, don't create it, throw out error.

CONNECT 'jdbc:derby://localhost:1527/data;user=alfred;password=alfred' AS BOULEVARD;

-- ### Use ij command to connect network server database, reading specific repository;

-- ### If not exist, create it.

CONNECT 'jdbc:derby://localhost:1527/D:/workspace/Boulevard/BoulevardDB/data;create=true;user=alfred;password=alfred' AS BOULEVARD;

-- ### Use ij command to connect network server database, reading specific repository;

-- ### If not exist, don't create it, throw out error.

CONNECT 'jdbc:derby://localhost:1527/D:/workspace/Boulevard/BoulevardDB/data;user=alfred;password=alfred' AS BOULEVARD;

------------------------------- Derby connection information -------------------------------

pixy.gif?x-id=284552ae-4a4b-864c-887c-acd0a107e7f2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值