1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Copyright 2004-2009 H2 Group. Multiple-Licensed under the H2 License, Version 1.0,
and under the Eclipse Public License, Version 1.0
(http://h2database.com/html/license.html).
Initial Developer: H2 Group
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>
H2 Database Engine
</title>
<style type="text/css">
td, input, select, textarea, body, td, th {
font: 9pt Tahoma, Arial, Helvetica, sans-serif;
font-weight: normal;
}
h1, h2, h3, h4, h5 {
font: 9pt Tahoma, Arial, Helvetica, sans-serif;
font-weight: bold;
}
h1 {
background-color: #0000bb;
padding: 2px 4px 2px 4px;
color: #fff;
font-size: 15pt;
line-height: normal;
}
h2 {
font-size: 10pt;
}
a.link {
text-decoration: underline;
color: blue;
}
a.link:hover {
text-decoration: underline;
color: blue;
}
a {
text-decoration: none;
color: black;
}
a:hover {
text-decoration: underline;
color: blue;
}
td, input, select, textarea, body, code, pre {
font-size: 9pt;
}
pre {
background-color: #ece9d8;
border: 1px solid rgb(172, 168, 153);
padding: 4px;
}
code {
background-color: #ece9d8;
padding: 0px 2px;
}
table {
background-color: #ffffff;
border-collapse: collapse;
border: 0px solid #aca899;
}
th {
text-align: left;
background-color: #ece9d8;
border: 1px solid #aca899;
padding: 2px;
}
td {
background-color: #ffffff;
text-align: left;
vertical-align: top;
border: 0px solid #aca899;
padding: 2px;
}
ul, ol {
list-style-position: outside;
padding-left: 20px;
}
li {
margin-top: 2px;
}
</style>
</head><body>
<div style="width:660px; margin:0 auto;">
<h1>H2 Database Engine Cheat Sheet</h1>
<div style="float:left; margin:5px; width:320px;">
<h2>Using H2</h2>
<ul><li><a href="http://h2database.com">H2</a> is
<a href="http://code.google.com/p/h2database/source">open source</a>,
<a href="license.html">free to use and distribute</a>.
</li><li><a href="http://h2database.com/html/download.html">Download</a>:
<a href="http://repo1.maven.org/maven2/com/h2database/h2/${version}/h2-${version}.jar" class="link">jar</a>,
<a href="http://www.h2database.com/h2-setup-${versionDate}.exe" class="link">installer (Windows)</a>,
<a href="http://www.h2database.com/h2-${versionDate}.zip" class="link">zip</a>.
</li><li>To start the
<a href="quickstart.html#h2_console">H2 Console tool</a>, double click the jar file, or
run <code>java -jar h2*.jar</code>, <code>h2.bat</code>, or <code>h2.sh</code>.
</li><li><a href="tutorial.html#creating_new_databases">A new database is automatically created</a>
<a href="features.html#database_only_if_exists">by default</a>.
</li><li><a href="features.html#closing_a_database">Closing the last connection closes the database</a>.
</li></ul>
<h2>Documentation</h2>
<p>
Reference:
<a href="grammar.html" class="link">SQL grammar</a>,
<a href="functions.html" class="link">functions</a>,
<a href="datatypes.html" class="link">data types</a>,
<a href="tutorial.html#command_line_tools" class="link">tools</a>,
<a href="../javadoc/index.html" class="link">API</a>
<br />
<a href="features.html">Features</a>:
<a href="tutorial.html#fulltext" class="link">fulltext search</a>,
<a href="features.html#file_encryption" class="link">encryption</a>,
<a href="features.html#read_only" class="link">read-only</a>
<a href="features.html#database_in_zip" class="link">(zip/jar)</a>,
<a href="tutorial.html#csv" class="link">CSV</a>,
<a href="features.html#auto_reconnect" class="link">auto-reconnect</a>,
<a href="features.html#triggers" class="link">triggers</a>,
<a href="features.html#user_defined_functions" class="link">user functions</a>
</p>
<h2><a href="features.html#database_url">Database URLs</a></h2>
<p>
<b><a href="features.html#connection_modes">Embedded</a></b><br />
<code>jdbc:h2:~/test</code> 'test' in the user home directory<br />
<code>jdbc:h2:/data/test</code> 'test' in the directory /data<br />
<code>jdbc:h2:test</code> in the current(!) working directory<br />
</p><p>
<b><a href="features.html#in_memory_databases">In-Memory</a></b><br />
<code>jdbc:h2:mem:test</code> multiple connections in one process<br />
<code>jdbc:h2:mem:</code> unnamed private; one connection<br />
</p><p>
<b><a href="tutorial.html#using_server">Server Mode</a></b><br />
<code>jdbc:h2:tcp://localhost/~/test</code> user home dir<br />
<code>jdbc:h2:tcp://localhost//data/test</code> absolute dir<br />
<a href="tutorial.html#using_server">Server start</a>:<code>java -cp *.jar org.h2.tools.Server</code>
</p><p>
<b><a href="features.html#database_url">Settings</a></b><br />
<code>jdbc:h2:..;MODE=MySQL</code> <a href="features.html#compatibility" >compatibility (or HSQLDB,...)</a><br />
<code>jdbc:h2:..;TRACE_LEVEL_FILE=3</code> <a href="features.html#trace_options">log to *.trace.db</a><br />
</p>
</div>
<div style="float:right; padding:5px; width:320px;">
<h2><a href="tutorial.html#connecting_using_jdbc">Using the JDBC API</a></h2>
<pre>
Class.forName("org.h2.Driver");
Connection conn = DriverManager.
getConnection("jdbc:h2:~/test");
conn.close();
</pre>
<h2><a href="tutorial.html#connection_pool">Connection Pool</a></h2>
<pre>
import org.h2.jdbcx.JdbcConnectionPool;
JdbcConnectionPool cp = JdbcConnectionPool.
create("jdbc:h2:~/test", "sa", "sa");
Connection conn = cp.getConnection();
conn.close(); cp.dispose();
</pre>
<h2><a href="build.html#maven2">Maven 2</a></h2>
<pre>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${version}</version>
</dependency>
</pre>
<h2><a href="tutorial.html#using_hibernate">Hibernate</a></h2>
<p>
hibernate.cfg.xml (or use the HSQLDialect):
</p>
<pre>
<property name="dialect">
org.hibernate.dialect.H2Dialect
</property>
</pre>
<h2><a href="tutorial.html#using_toplink">TopLink and Glassfish</a></h2>
<p>
Datasource class: <code>org.h2.jdbcx.JdbcDataSource</code><br />
<code>oracle.toplink.essentials.platform.</code><br />
<code>database.H2Platform</code>
</p>
</div>
</div>
</body></html>