Tuesday, August 30, 2011

Hibernate Configuration for Derby DataBase

Derby is a pure Java relational database engine using standard SQL and JDBC as its APIs

Download latest release of derby database from  http://db.apache.org/derby/releases/

Download the zip version, Extract the zip file and set classpath to environment variables.

Table 1. Commands to run the startNetworkServer command
Operating System Command
set DERBY_HOME=C:\derby
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_24
UNIX (Korn Shell)
export DERBY_HOME=/opt/derby
export JAVA_HOME=/usr/j2se
export PATH="$DERBY_HOME/bin:$PATH"

we can find, more details in the following link

Use startNetworkServer command to run the derby database.

Hibernate Configuration

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        <property name="dialect">
        <property name="connection.url">
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <property name="connection.driver_class">
        <property name="hbm2ddl.auto">update</property>
        <mapping resource="EmpTO.hbm.xml" />

By default, the Derby Network Server only accepts requests from the localhost on port 1527

The following is the database connection URL syntax for Java DB:
  • subsubprotocol specifies where Java DB should search for the database, either in a directory, in memory, in a class path, or in a JAR file. It is typically omitted.
  • databaseName is the name of the database to connect to.
  • attribute=value represents an optional, semicolon-separated list of attributes. These attributes enable you to instruct Java DB to perform various tasks, including the following:
    • Create the database specified in the connection URL.
    • Encrypt the database specified in the connection URL.
    • Specify directories to store logging and trace information.
    • Specify a user name and password to connect to the database.
Java DB: jdbc:derby://localhost:1527/testdb;create=true, where testdb is the name of the database to connect to, and create=true instructs the DBMS to create the database.

No comments :

Post a Comment