Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
455544f2
提交
455544f2
authored
4月 07, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve documentation
上级
69f143ed
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
102 行增加
和
94 行删除
+102
-94
download.html
h2/src/docsrc/html/download.html
+0
-2
features.html
h2/src/docsrc/html/features.html
+2
-2
links.html
h2/src/docsrc/html/links.html
+6
-0
stylesheet.css
h2/src/docsrc/html/stylesheet.css
+1
-0
tutorial.html
h2/src/docsrc/html/tutorial.html
+93
-90
没有找到文件。
h2/src/docsrc/html/download.html
浏览文件 @
455544f2
...
...
@@ -9,8 +9,6 @@ Initial Developer: H2 Group
<head><meta
http-equiv=
"Content-Type"
content=
"text/html;charset=utf-8"
/><title>
Downloads
</title><link
rel=
"stylesheet"
type=
"text/css"
href=
"stylesheet.css"
/>
<link
rel=
"alternate"
type=
"application/atom+xml"
title=
"H2 Newsfeed (Atom)"
href=
"http://www.h2database.com/html/newsfeed-atom.xml"
/>
<link
rel=
"alternate"
type=
"application/rss+xml"
title=
"H2 Newsfeed (RSS)"
href=
"http://www.h2database.com/html/newsfeed-rss.xml"
/>
<!-- [search] { -->
<script
type=
"text/javascript"
src=
"navigation.js"
></script>
</head><body
onload=
"frameMe();"
>
...
...
h2/src/docsrc/html/features.html
浏览文件 @
455544f2
...
...
@@ -1182,12 +1182,12 @@ open, one of them will then start a server (auto-reconnect is enabled automatica
<p>
This mode has three disadvantages: All processes need to have access to the database files.
Then, if the first connection is closed (the connection that started the server), open transactions of
other connections will be rolled back.
other connections will be rolled back.
Also, explicit client/server connections (using jdbc:h2:tcp:// or ssl://) are not supported.
</p>
<p>
Here is an example how to use this mode. Application 1 and 2 are not necessarily started
on the same computer, but they need to have access to the database files. Application 1
on the same computer, but they need to have access to the database files. Application 1
and 2 are typically two different processes (however they could run within the same process).
</p>
<pre>
...
...
h2/src/docsrc/html/links.html
浏览文件 @
455544f2
...
...
@@ -168,6 +168,12 @@ Blojsom</a><br />
Java-based multi-blog, multi-user software package (Mac OS X Weblog Server).
</p>
<p><a
href=
"http://wiki.bonita.ow2.org/xwiki/bin/view/Main"
>
Bonita
</a><br
/>
Open source workflow solution for handing long-running, user-oriented processes
providing out of the box workflow and business process management features.
</p>
<p><a
href=
"http://bmarks-portlet.sourceforge.net"
>
Bookmarks Portlet
</a><br
/>
JSR 168 compliant bookmarks management portlet application.
...
...
h2/src/docsrc/html/stylesheet.css
浏览文件 @
455544f2
...
...
@@ -36,6 +36,7 @@ img {
body
{
margin
:
0px
;
max-width
:
800px
;
}
h1
{
...
...
h2/src/docsrc/html/tutorial.html
浏览文件 @
455544f2
...
...
@@ -65,7 +65,8 @@ This is a client / server application, so both a server and a client (a browser)
</p><p>
Depending on your platform and environment, there are multiple ways to start the application:
</p>
<table><tr><th>
OS
</th><th>
Start
</th></tr>
<table>
<tr><th>
OS
</th><th>
Start
</th></tr>
<tr>
<td>
Windows
</td>
<td>
...
...
@@ -75,7 +76,7 @@ Depending on your platform and environment, there are multiple ways to start the
<img
src=
"images/db-16.png"
alt=
"[H2 icon]"
/><br
/>
If you don't get the window and the system tray icon,
then maybe Java is not installed correctly (in this case, try another way to start the application).
A browser window should open and point to the Login page
http://localhost:8082)
.
A browser window should open and point to the Login page
at http://localhost:8082
.
</td>
</tr>
<tr>
...
...
@@ -87,13 +88,18 @@ Depending on your platform and environment, there are multiple ways to start the
(URL: http://localhost:8082).
</td>
</tr>
<tr>
<td>
Any
</td>
<td>
Double click on the h2*.jar file.
This only works if the .jar suffix is associated with java.
</td>
</tr>
<tr>
<td>
Any
</td>
<td>
Open a console window, navigate to the directory 'h2/bin' and type:
<pre>
java -cp h2*.jar org.h2.tools.Server
</pre>
<pre>
java -cp h2*.jar org.h2.tools.Server
</pre>
</td>
</tr>
</table>
...
...
@@ -116,13 +122,6 @@ A small firewall is already built into the server: other computers may not conne
To change this, go to 'Preferences' and select 'Allow connections from other computers'.
</p>
<h3>
Native Version
</h3>
<p>
The native version does not require Java, because it is compiled using GCJ.
However H2 does currently not run stable with GCJ on Windows
It is possible to compile the software to different platforms.
</p>
<h3>
Testing Java
</h3>
<p>
To check the Java version you have installed, open a command prompt and type:
...
...
@@ -134,11 +133,11 @@ java -version
If you get an error message, you may need to add the Java binary directory to the path environment variable.
</p>
<h3>
Error Message 'Port
is
in use'
</h3>
<h3>
Error Message 'Port
may be
in use'
</h3>
<p>
You can only start one instance of the H2 Console,
otherwise you will get the following error message:
<code>
Port is in use, maybe another ... server already running on
...
</code>
.
<code>
The Web server could not be started. Possible cause: another server is already running
...
</code>
.
It is possible to start multiple console applications on the same computer (using different ports),
but this is usually not required as the console supports multiple concurrent connections.
</p>
...
...
@@ -151,27 +150,14 @@ in the user directory (for Windows, this is usually in "Documents and Settings/&
The relevant entry is webPort.
</p>
<h3>
Starting Successfully
</h3>
<p>
If starting the server from a console window was successful,
a new window will open and display the following text:
</p>
<pre>
H2 Server running on port 9092
Webserver running on https://localhost:8082/
</pre>
<p>
Don't click inside this window; otherwise you might block the application (if you have the Fast-Edit mode enabled).
</p>
<h3>
Connecting to the Server using a Browser
</h3>
<p>
If the server started successfully, you can connect to it using a web browser.
The browser needs to support JavaScript, frames and cascading stylesheets (css)
.
If you started the server on the same computer as the browser,
go to http://localhost:8082 in the browser
.
JavaScript needs to be enabled
.
If you started the server on the same computer as the browser,
open the URL http://localhost:8082
.
If you want to connect to the application from another computer, you need to provide the IP address of the server, for example:
<a
href=
"http://192.168.0.2:8082"
>
http://192.168.0.2:8082
</a>
.
If you enabled SSL on the server side, the URL needs to start with
HTTPS
.
http://192.168.0.2:8082
.
If you enabled SSL on the server side, the URL needs to start with
https://
.
</p>
<h3>
Multiple Concurrent Sessions
</h3>
...
...
@@ -186,8 +172,8 @@ At the login page, you need to provide connection information to connect to a da
Set the JDBC driver class of your database, the JDBC URL, user name and password.
If you are done, click [Connect].
</p><p>
You can save and reuse previously saved settings. The settings are stored in
th
e
Application Properties file
.
You can save and reuse previously saved settings. The settings are stored in
a properties fil
e
(see
<a
href=
"#console_settings"
>
Settings of the H2 Console
</a>
)
.
</p>
<h3>
Error Messages
</h3>
...
...
@@ -207,9 +193,9 @@ Multiple drivers can be set; each entry needs to be separated with a ';' (Window
Spaces in the path names are supported. The settings must not be quoted.
</p>
<h3>
Using the
Application
</h3>
<h3>
Using the
H2 Console
</h3>
<p>
The
application has three main panels, the toolbar on top, the tree on the left
and the query / result panel on the right.
The
H2 Console application has three main panels: the toolbar on top, the tree on the left,
and the query / result panel on the right.
The database objects (for example, tables) are listed on the left panel.
Type in a SQL command on the query panel and click 'Run'. The result of the command appears just below the command.
</p>
...
...
@@ -224,12 +210,13 @@ For, example if you type 'SELECT * FROM TEST T WHERE T.' then the table TEST is
<h3>
Disconnecting and Stopping the Application
</h3>
<p>
On the browser, click 'Disconnect' on the toolbar panel. You will be logged out of the database
.
To log out of the database, click 'Disconnect' in the toolbar panel
.
However, the server is still running and ready to accept new sessions.
</p><p>
To stop the server, right click on the system tray icon and select [Exit].
If you don't have the icon (because you started it in another way),
press [Ctrl]+[C] on the console where the server was started (Windows),
If you don't have the system tray icon,
navigate to [Preferences] and click [Shutdown],
press [Ctrl]+[C] in the console where the server was started (Windows),
or close the console window.
</p>
...
...
@@ -257,17 +244,18 @@ public class Test {
Connection conn = DriverManager.
getConnection("jdbc:h2:~/test", "sa", "");
// add application code here
conn.close();
}
}
</pre>
<p>
This code first loads the driver (
<code>
Class.forName()
</code>
)
This code first loads the driver (
<code>
Class.forName(
...
)
</code>
)
and then opens a connection (using
<code>
DriverManager.getConnection()
</code>
).
The driver name is
<code>
"org.h2.Driver"
</code>
in every case
.
The driver name is
<code>
"org.h2.Driver"
</code>
.
The database URL always needs to start with
<code>
jdbc:h2:
</code>
to be recognized by this database. The second parameter in the
<code>
getConnection()
</code>
call
is the user name ('sa' for System Administrator in this example). The third parameter is the password.
Please note that in this database, user names are not case sensitive, but passwords are case sensitiv
e.
In this database, user names are not case sensitive, but passwords ar
e.
</p>
<br
/><a
name=
"creating_new_databases"
></a>
...
...
@@ -281,26 +269,27 @@ the administrator of this database.
<br
/><a
name=
"using_server"
></a>
<h2>
Using the Server
</h2>
<p>
H2 currently supports three servers: a Web Server, a TCP Server and an ODBC Server.
The servers can be started in different ways.
H2 currently supports three server: a web server (for the H2 Console),
a TCP server (for client/server connections) and an PG server (for PostgreSQL clients).
The servers can be started in different ways, one is using the server tool.
</p>
<h3>
Starting the Server from Command Line
</h3>
<h3>
Starting the Server
Tool
from Command Line
</h3>
<p>
To start the
Server from the command line with the default settings, run
To start the
server tool from the command line with the default settings, run:
</p>
<pre>
java org.h2.tools.Server
java
-cp h2*.jar
org.h2.tools.Server
</pre>
<p>
This will start the
Server with the default options. To get the list of options and default values, run
This will start the
server tool with the default options. To get the list of options and default values, run:
</p>
<pre>
java org.h2.tools.Server -?
java
-cp h2*.jar
org.h2.tools.Server -?
</pre>
<p>
There are options available to use
different
ports, and start or not start
parts
of the Server and so on. For details, see the API documentation of the S
erver tool.
There are options available to use
other
ports, and start or not start
parts
. For details, see the API documentation of the s
erver tool.
</p>
<h3>
Connecting to the TCP Server
</h3>
...
...
@@ -315,9 +304,9 @@ To remotely connect to a database using the TCP server, use the following driver
For details about the database URL, see also in Features.
</p>
<h3>
Starting the Server within an Application
</h3>
<h3>
Starting the
TCP
Server within an Application
</h3>
<p>
It is also possible to start and stop a Server
from within an application. Sample code:
Servers can also be started and stopped
from within an application. Sample code:
</p>
<pre>
import org.h2.tools.Server;
...
...
@@ -331,7 +320,7 @@ server.stop();
<h3>
Stopping a TCP Server from Another Process
</h3>
<p>
The TCP
S
erver can be stopped from another process.
The TCP
s
erver can be stopped from another process.
To stop the server from the command line, run:
</p>
<pre>
...
...
@@ -344,10 +333,13 @@ To stop the server from a user application, use the following code:
org.h2.tools.Server.shutdownTcpServer("tcp://localhost:9094");
</pre>
<p>
This function will call System.exit on the server.
This function should be called after all connections to the databases are closed
to avoid recovery when the databases are opened the next time.
To stop remote server, remote connections must be enabled on the server.
This function will only stop the TCP server.
If other server were started in the same process, they will continue to run.
To avoid recovery when the databases are opened the next time,
all connections to the databases should be closed before calling this method.
To stop a remote server, remote connections must be enabled on the server.
Shutting down a TCP server can be protected using the option -tcpPassword
(the same password must be used to start and stop the TCP server).
</p>
<br
/><a
name=
"using_hibernate"
></a>
...
...
@@ -423,8 +415,8 @@ The server mode is similar, but it allows you to run the server in another proce
<h3>
Using a Servlet Listener to Start and Stop a Database
</h3>
<p>
Add the h2*.jar file your web application, and
add the following snippet to your web.xml file (
after context-param and before filter
):
Add the h2*.jar file
to
your web application, and
add the following snippet to your web.xml file (
between the 'context-param' and the 'filter' section
):
</p>
<pre>
<
listener>
...
...
@@ -433,8 +425,9 @@ add the following snippet to your web.xml file (after context-param and before f
</pre>
<p>
For details on how to access the database, see the file DbStarter.java.
By default the DbStarter listener opens an embedded connection using the database URL jdbc:h2:~/test
and user name and password 'sa'. If you want to use it within your servlet, you can access it like this:
By default the DbStarter listener opens an embedded connection
using the database URL 'jdbc:h2:~/test', user name 'sa', and password 'sa'.
If you want to use this connection within your servlet, you can access as follows:
</p>
<pre>
Connection conn = getServletContext().getAttribute("connection");
...
...
@@ -442,7 +435,7 @@ Connection conn = getServletContext().getAttribute("connection");
<p>
The DbStarter can also start the TCP server, however this is disabled by default.
To enable it, use the parameter db.tcpServer in the file web.xml. Here is the complete list of options.
These options
are set just after the display-name and description tag, but before any listener and filter
tags:
These options
need to be placed between the 'description' tag and the 'listener' / 'filter'
tags:
</p>
<pre>
<
context-param>
...
...
@@ -464,8 +457,7 @@ These options are set just after the display-name and description tag, but befor
</pre>
<p>
When the web application is stopped, the database connection will be closed automatically.
If the server is started within the DbStarter, it will also be stopped automatically when the
web application is stopped.
If the TCP server is started within the DbStarter, it will also be stopped automatically.
</p>
<h3>
Using the H2 Console Servlet
</h3>
...
...
@@ -489,7 +481,7 @@ add the following configuration to your web.xml:
For details, see also
<code>
src/tools/WEB-INF/web.xml
</code>
.
</p>
<p>
To create a web application
that creates
just the H2 Console, run the following command:
To create a web application
with
just the H2 Console, run the following command:
</p>
<pre>
build warConsole
...
...
@@ -499,7 +491,7 @@ build warConsole
<h2>
CSV (Comma Separated Values) Support
</h2>
<p>
The CSV file support can be used inside the database using the functions CSVREAD and CSVWRITE,
and the CSV library
can be used outside the database as a standalone tool.
or it
can be used outside the database as a standalone tool.
</p>
<h3>
Writing a CSV File from Within a Database
</h3>
...
...
@@ -527,16 +519,19 @@ The CSV tool can be used in a Java application even when not using a database at
Example:
</p>
<pre>
import java.sql.*;
import org.h2.tools.Csv;
import org.h2.tools.SimpleResultSet;
...
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
rs.addColumn("PHONE", Types.VARCHAR, 255, 0);
rs.addRow(new String[] { "Bob Meier", "bob.meier@abcde.abc", "+41123456789" });
rs.addRow(new String[] { "John Jones", "john.jones@abcde.abc", "+41976543210" });
Csv.getInstance().write("data/test.csv", rs, null);
public class TestCsv {
public static void main(String[] args) throws Exception {
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("NAME", Types.VARCHAR, 255, 0);
rs.addColumn("EMAIL", Types.VARCHAR, 255, 0);
rs.addRow(new String[] { "Bob Meier", "bob.meier@abcde.abc" });
rs.addRow(new String[] { "John Jones", "john.jones@abcde.abc" });
Csv.getInstance().write("data/test.csv", rs, null);
}
}
</pre>
<h3>
Reading a CSV File from a Java Application
</h3>
...
...
@@ -545,17 +540,24 @@ It is possible to read a CSV file without opening a database.
Example:
</p>
<pre>
import java.sql.*;
import org.h2.tools.Csv;
...
ResultSet rs = Csv.getInstance().read("data/test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
for (int i = 0; i
<
meta.getColumnCount(); i++) {
System.out.println(meta.getColumnLabel(i + 1) + ": " + rs.getString(i + 1));
public class TestCsv {
public static void main(String[] args) throws Exception {
ResultSet rs = Csv.getInstance().
read("data/test.csv", null, null);
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
for (int i = 0; i
<
meta.getColumnCount(); i++) {
System.out.println(
meta.getColumnLabel(i + 1) + ": " +
rs.getString(i + 1));
}
System.out.println();
}
rs.close();
}
System.out.println();
}
rs.close();
</pre>
<br
/><a
name=
"upgrade_backup_restore"
></a>
...
...
@@ -636,15 +638,15 @@ The command line tools are:
</li><li><b>
ConvertTraceFile
</b>
converts a .trace.db file to a Java application and SQL script.
</li><li><b>
CreateCluster
</b>
creates a cluster from a standalone database.
</li><li><b>
DeleteDbFiles
</b>
deletes all files belonging to a database.
</li><li><b>
Script
</b>
allows converting a database to a SQL script for backup or migration.
</li><li><b>
Recover
</b>
helps recovering a corrupted database.
</li><li><b>
Restore
</b>
restores a backup of a database.
</li><li><b>
RunScript
</b>
runs a SQL script against a database.
</li><li><b>
Script
</b>
allows converting a database to a SQL script for backup or migration.
</li><li><b>
Server
</b>
is used in the server mode to start a H2 server.
</li><li><b>
Shell
</b>
is a command line database tool.
</li></ul>
<p>
The tools can also be called from an application by calling the main or another public method
s
.
The tools can also be called from an application by calling the main or another public method.
For details, see the Javadoc documentation.
</p>
...
...
@@ -661,7 +663,7 @@ The steps to connect to a H2 database are:
</li><li>
Select your h2 jar file (location is up to you, could be wherever you choose)
</li><li>
Click [OK] (as much as needed), stop OpenOffice (including the Quickstarter)
</li><li>
Start OpenOffice Base
</li><li>
Connect to an existing database; select
JDBC
; [Next]
</li><li>
Connect to an existing database; select
[JDBC]
; [Next]
</li><li>
Example datasource URL: jdbc:h2:~/test
</li><li>
JDBC driver class: org.h2.Driver
</li></ul>
...
...
@@ -673,16 +675,17 @@ To use H2 in NeoOffice (OpenOffice without X11):
</p>
<ul><li>
In NeoOffice, go to [NeoOffice], [Preferences]
</li><li>
Look for the page under [NeoOffice], [Java]
</li><li>
Click [Class
p
ath], [Add Archive...]
</li><li>
Click [Class
P
ath], [Add Archive...]
</li><li>
Select your h2 jar file (location is up to you, could be wherever you choose)
</li><li>
Click [OK] (as much as needed), restart NeoOffice.
</li></ul>
<p>
Now, when creating a new database using the "Database Wizard":
Now, when creating a new database using the "Database Wizard"
:
</p>
<ul><li>
Select "connect to existing database" and the type "jdbc". Click next.
</li><li>
Enter your h2 database URL. The normal behavior of H2 is that a new db is created if it doesn't exist.
</li><li>
Next step - up to you... you can just click finish and start working.
<ul><li>
Click [File], [New], [Database].
</li><li>
Select [Connect to existing database] and the select [JDBC]. Click next.
</li><li>
Example datasource URL: jdbc:h2:~/test
</li><li>
JDBC driver class: org.h2.Driver
</li></ul>
<p>
Another solution to use H2 in NeoOffice is:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论