## How To Setup A C-JDBC Database Cluster

Note: for further information about configuration of a RAIDB1 C-JDBC cluster, refer to the C-JDBC documentation. This configuration starts three HSQLDB instances that are formed by C-JDBC as RAIDB1. This means that the same data is stored in two different databases and one database is used as a recovery log.

1. Download the C-JDBC binaries from the C-JDBC Forge site.
2. Extract the C-JDBC archive in a folder.
   `tar xvfz c-jdbc-xx-bin.tar.gz`
3. Set the environment variables.
   `export JAVA_HOME=<Path to JDK HOME>`
   `export CJDBC_HOME=<Path to the CJDBC HOME>`
4. Modify the `$CJDBC_HOME/demo/demo-raidb1.sh` file.
   The ports for the HSQLDB instances must be modified to match the `sampleCluster2` configuration. Change the ports for the three databases to `11001, 11002, 11003`.
5. Edit the C-JDBC virtual database file:
   `$CJDBC_HOME/config/virtualdatabase/hsqldb-raidb1.xml`
   Modify the ports according to the values defined in the section above. To avoid problems in the Datasource configuration of JOnAS, you must also set a password for the user to log in (`VirtualLogin` element). Warning if you choose another username than default value `user`, modify also the `vLogin` attribute of `ConnectionManager` elements.
6. Start the cluster (HSQLDB instances and then C-JDBC controller).
   `$CJDBC_HOME/demo/demo-raidb1.sh`
7. Connect to the C-JDBC controller using the JDBC driver (`$CJDBC_HOME/drivers/c-jdbc-driver.jar`) and the URL:
   `jdbc:cjdbc://localhost:25322/myDB` with `username: <user>` and `password: <pass>`
   Use the password you set in `$CJDBC_HOME/config/virtualdatabase/hsqldb-raidb1.xml` file.

   Sample C-JDBC DataSource configuration file to use in JOnAS:

       ###################### C-JDBC DataSource configuration example
       #
       #####
       #DataSource configuration
       #
       #datasource.name jdbc_1
       datasource.url jdbc:cjdbc://localhost:25322/myDB
       datasource.classname org.objectweb.cjdbc.driver.Driver
       datasource.username user
       datasource.password pass
       # WARNING: you must specify the mapper of the databases used as
       # backend by C-JDBC. It is not possible to use a heterogenious c-jdbc
       # configuration here.
       datasource.mapper rdb.hsql