6.12 Embedded Database Engine

SmartFoxServer 1.6 comes together with an embedded high-performance, ultra-light database engine called H2 Database Engine.

The database server is fully JDBC compliant: it comes with its own JDBC driver and a convenient web-based administration tool. In other words with SmartFoxServer 1.6 you don't have to worry about setting up and running a separate DB server like MySQL or MSSQL. The H2 engine is already configured and ready for use as soon as SFS is started.

The H2 engine is also useful for prototyping your applications, as you will be able to switch to any other JDBC production database, by simply changing a couple of settings in the main config.xml file.

» Creating a new database

In order to execute the H2 admin tool you should launch the adminDb script found in the Server/ folder, while SmartFoxServer is running.

» Under Windows:

double click the adminDb.bat file in the Server/ folder

» Under Linux / Unix:
from a terminal window run the adminDb.sh script by typing ./adminDb.sh

This will start the admin tool and should launch a browser window that looks like this:

DbAdmin

The most important part is the JDBC URL. In this case: jdbc:h2:tcp://localhost:9009/examples
Let's go through each part of the url and let's see what each bit means:

If a database with the specified name already exists you will connect to it, otherwise a new database with that name will be created.

The examples database is provided with a demo table called "retrocomputers". This is how the admin tool looks like when connected to the demo table:

H2db

» Database security

The H2 Database Engine is configured to run exclusively on the localhost using port 9009. Any other attempt to establish a connection from other ip addresses will be refused so the server is never exposed to the outside world.

In the Server/ folder you will find a datastore/ directory where all the files used by H2 are stored. In case you need to migrate the database data to another SmartFoxServer instance you should also move that directory as well.

» H2 documentation and more...

The H2 database engine comes with detailed documentation and user manual the can be consulted on the official website. We highly recommend to visit their site for further details about the SQL grammar, built-in functions and performance analysis.

Check also the H2 database tutorial coming with source code.

 


doc index