Wiki source code of H2 Installation

Last modified by Vincent Massol on 2017/09/06

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 [[H2>>http://h2database.com]] is a fast, free, in-memory or disk-based java database.
6
7 Follow these instructions to use it with XWiki:
8
9 * H2 is a very simple database to configure as you don't need to install nor to start it before being able to use it. It comes as a single JAR file named ##h2*.jar##. You'll need to [[download this JAR>>http://www.h2database.com/html/download.html]] and copy it in your ##WEB-INF/lib## directory.
10 * Once this is done, you need to configure XWiki to use H2 and to tell it where the database files will be created. To do this, edit the ##WEB-INF/hibernate.cfg.xml## file where you have expanded the XWiki WAR file and uncommented the H2 part. If you're using an old version of XWiki you won't find a commented out section for H2. In this case, use the following:(((
11 {{code language="xml"}}
12 <property name="connection.url">jdbc:h2:${environment.permanentDirectory}/database/xwiki</property>
13 <property name="connection.username">sa</property>
14 <property name="connection.password"></property>
15 <property name="connection.driver_class">org.h2.Driver</property>
16 <property name="dialect">org.hibernate.dialect.H2Dialect</property>
17 {{/code}}
18 )))
19
20 = Using a JDBC DataSource =
21
22 {{code language="xml"}}
23 <property name="connection.datasource">java:comp/env/jdbc/XWikiDS</property>
24 <property name="dialect">org.hibernate.dialect.H2Dialect</property>
25 {{/code}}
26
27 = Using a remote H2 instance =
28
29 {{code language="xml"}}
30 <property name="connection.url">jdbc:h2:tcp://remotehost/xwiki23</property>
31 {{/code}}
32
33 On the H2 side, here's one way to have H2 running on a remote machine:
34
35 {{code language="bash"}}
36 java -cp ./h2-1.2.136.jar org.h2.tools.Server -web -tcp -tcpAllowOthers -baseDir /var/spool/javadb/h2
37 {{/code}}
38
39 Thus any database you create will be stored in this location, so with the above example you will have a database called ##/var/spool/javadb/h2/xwiki23##.

Get Connected