Saturday, 17 August 2013

Set relative path from context.xml to look for HSQLDB connection with JNDI

Set relative path from context.xml to look for HSQLDB connection with JNDI

I am trying to set up a webapp with JNDI looking up a datasource specified
via context.xml.
The connection is supposed to be build in in-process mode with HSQLDB
I don't want to use server mode, as I want the the db to be portable with
the project, and in-process is of higher performance than server-mode.
My META-INF/context.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project>
<Context>
<Resource name="jdbc/testdb"
auth="Container" type="javax.sql.DataSource"
username="sa" password=""
driverClassName="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:file:${catalina.base}/wtpwebapps/LoginExample/db/testdb"
maxActive="10" maxIdle="4" />
</Context>
The location of my DB in my webapp project is as follows:

The database is in my WebContent, so when it is deployed, it should be the
above specified relative path in the connection URL.
My question is:
Is this the best way to specify a relative address in the URL to access my
HSQLDB? or if there should be a better practice?
Thanks
p.s. I want the DB to be editable, so src-mode is out of question.

No comments:

Post a Comment