Pursuing

Alfred’s weblog

An Derby Properties and Connection URL Example

Have been using Derby for a long time, which is a very good choice as memory database or embedded database, let me backup some useful Derby DB Properties here:

Developer can use a derby.properties file in the application classpath or javadb classpath to configure the database, these are some configuration examples in the file:

—————————- 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=8192
derby.storage.pageReservedSpace=60
derby.database.defaultConnectionMode
derby.locks.deadlockTimeout=20
derby.locks.waitTimeout=30
—————————- Derby derby.properties information —————————-

You have 2 ways to start the database:

1. Start embedded Derby from java application. The database is active from the first time you connect to it, and become inactive when your java application stop; and any other application outside of the same JVM can not access the database instance.

To connect to embedded Derby by URL:
——————————- 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. Start Derby network server. The network server instance can only be started by command “…\javadb\bin\startNetworkServer.bat”, and it runs as a server which will not stop when your application stops; and other applications in any JVM can also access the database locally or remotely.

To connect to Derby network server:
——————————- 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 ——————————-

Advertisements

April 16, 2009 - Posted by | Specialty | , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: