Blog Archives

Apache Derby Part 3

You can use the SQL client tool, such as “SQuirreL SQL Client” for creating the tables and managing your data. At the first time, even you log in as your decided user name, the schema that related to user name has not be presented. It will presented after you have finished creating a least one table. My previous post mention about “the system will prompt you to provide the default schema, at the moment please choose “APP”. At the moment, you have your own schema which is related to your user name already. After you connect to your database via NetBeans you can extract your connection node and choose your schema as a default schema by right click at the schema which same as your user name and choose “Set as Default Schema”. It’s nice to create some tables for further using via the JPA. I prefer to have at least 3 tables as following: –

1. The master table as a parent.

2. The detail table as a child of the master with one-to-many relationship.

3. The lookup table for the master table with one-to-one relationship, e.g. the constant table which contains code and description.

Since someone told me that there is an interesting feature for Java EE 6: JPA 2.0, so that you can manage the child data via the POJO accessing through LIST or COLLECTION e.g. create new elements, update or delete elements. When save the parent object, all related child objects changing will be applied automatically without any line of code. I’m not sure if it is called “Cascading Persist” or not.

Later I will find further information and try my best to prove it.

Advertisements

Apache Derby Part 2

I would like to highlight, if you have finished installed the netbeans 6.8 together with the Glassfish V3, The Apache Derby is installed for your development automatically, it is named JavaDB. Anyhow when you move to the SIT/UAT/PROD, it should has a dedicated database server. Then it may nice if you have an experience and familiar about it instead of only the default development environment.

The database creation:

Case1 : use the pre-installed by netbeans 6.8 and GF v3

The database location:

You can find it by navigating through netbeans by following step: –

1. Go to “Services” –> “Databases” —> “Java DB“.

2. Right click at “Java DB” node, at the pop-up menu choose “properties“. The system will give you information about “Java DB Installation path” and “Database Location“.

The database version:

As my tracing through the netbeans as the following step: –

1. Go to “Services” –> “Databases” —> “Drivers” —> “Java DB (Network)

2. Right click at “Java DB (Network)” node, at the pop-up menu choose “customize“. The system will give you a location of Apache Derby JDBC jar file.

3. After I had got the “MANIFEST.MF” from that jar file, I got the information it is a version 10.5.3

The database creation:

1. Go to “Services” –> “Databases” —> “Java DB“.

2. Right click at “Java DB” node, at the pop-up menu choose “Create Database…“.  The system will prompt you to provide information about “Database Name“, “User Name” and “Password“. Please note it will give you a “Database Location” as well.

3. The “Connection” to the created database will be added to your environment automatically. For example, you may see this connection information.

“jdbc:derby://localhost:1527/[your db name]”

Case2 : use the separated installed

The database location:

By default, it is a folder that you execute the command to start the Apache Derby. Later I will mention how to customize.

The database version:

Regarding to my previous post, it is a version 10.6

The new driver registration:

Since the default driver is version 10.5.3 as I mentioned above, the version 10.6 driver should be registered by the following step: –

1. Go to “Services” –> “Databases” —> “Drivers

2. Right click at the “Drivers” node, at the pop-up menu choose “New Driver…“. The system will prompt you to provide the following information:-

Driver File“: The full path to the “derbyclient.jar”, by default it is in [Derby_Home]/lib”

Driver Class“: The will be selected automatically by the system, Anyhow you are allowed to change.

Name“: The display name of your new registered driver.

The database creation during the connection is performed:

1. Go to “Database

2. Right click at “Database“node, at the pop-up menu choose “New Connection…“. The system will prompt you to provide the following information.

Data Input Mode“: I prefer choosing “Field Entry“. If you have an experience about it, you can prefer “Direct URL Entry“.

Driver Name“: Choose you previous created.

Host“: I prefer localhost

Port“: I prefer default port 1527.

Database“: The database name. Please note, if you provide only name, the database will be store at the default location. Anyhow you can specify the full path to your decided location. For example

c:/[My_Location]/[My_DB_Name]

User Name“:

Password“:

Additional Props“: I prefer “create=true“. If you have any any additional property, it can be separated by comma “,”. Please note, this option will create the database automatically
along with the specified user name and password respectively. If the database is crated once, this option will be ignored.

Show JDBC URL“: I prefer to check this checkbox and copy the JDBC URL for further using, such as the database management via the “SQuirreL SQL Client” or other tools.

3. Click “OK” when you finish,the system will create the database if it is not exited. The system will prompt you to provide the default schema, at the moment please choose “APP“.

At the moment you have finished creating your own database. The next post will take you to create tables. Please stay tuned.

Apache Derby Part 1

Preparation:

You need to download the latest official released of Apache Derby here.

It is archived as a ZIP and TAR.GZ format, Since I’m in the Windows
environment,I choose the ZIP format. Please note, it’s nice to download
all thing for further deploying on the multi-platform environment.

Installation:

It is a ready to run,then you can extract it to your decided folder.

Overview:

The extracted folder contains a very useful documentation for getting
starting as [Derby_Home]/docs. There are both of HTML and PDF. The rest of
this post will follows the [Derby_Home]/docs/pdf/getstart/getstartderby.pdf
and [Derby_Home]/docs/pdf/adminguide/derbyadmin.pdf

Quick First Run:

Go to the [Derby_Home]/bin and execute the “startNetworkServer“,It will
be listen on the default port as 1527. Please note:

– By default it will listen to the requests only on loopback(localhost) address.

– You need to execute the “StopNetworkServer” everytimes when you finish using.

– If you would like to let it listen on the difference port, please use
the following command for starting up.

startNetworkServer -p [port]

– If you would like to let it listing on difference host and port, please
use the following command for starting up.

startNetworkServer -h [host] -p [port] ; [host] is a host name or IP

– If you start with the additional option, such as -p and/or -h, You need
to provide the same option to the “stopNetworkServer” as well. For example

stopNetworkServer -p [port]

stopNetworkServer -h [host] -p [port]

At the moment you have finished preparing the Apache Derby already, the next
post on part 2 will take you to create the database. Anyhow it’s nice to capture
the 2 previous mentioned documents before move to the next.

%d bloggers like this: