How can i run the H2 database in server mode?

6,792 views
Skip to first unread message

Ro

unread,
Aug 11, 2008, 7:35:18 AM8/11/08
to H2 Database
hi all,

i have connected to h2 database from java program. Then i am
able to do all the operations on H2 database through my program.
And My code is:-------------
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/
test", "sa", "");


Now the problem is that I want to operate H2 database through H2
browser. So i opened the http://localhost:8082.
But i came to know that H2 database is not started. so i started the
H2 database by using h2.bat file.
then i opened the http://localhost:8082 link to open the H2 browser.
then i a getting an error.
Error is:-------------------
Database may be already in use: Locked by another process. Possible
solutions: close all other connection(s); use the server mode
[90020-76] 90020/90020 (Help)


Then i copied my h2.jar file to my web application lib directory and
i added the listener into my web.xml of my web application. (Like
Explained in the h2 documentation)

But also i am getting the same error.


Plz help me out..................................

Nico

unread,
Aug 11, 2008, 8:40:08 AM8/11/08
to H2 Database
Hi,

I think you have to start a server instance and then use the tcp
protocol to connect. Something like :

Server server = Server.createTcpServer(new String {"-
tcpAllowOthers"}).start();
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/
~/test", "sa", "");


On 11 août, 13:35, Ro <rohinik...@gmail.com> wrote:
> hi all,
>
>        i have connected to h2 database from java program. Then i am
> able to do all the operations on H2 database through my program.
> And My code is:-------------
>          Class.forName("org.h2.Driver");
>          Connection conn = DriverManager.getConnection("jdbc:h2:~/
> test", "sa", "");
>
> Now the problem is that I want to operate H2 database through H2
> browser. So i opened thehttp://localhost:8082.
> But i came to know that H2 database is not started. so i started the
> H2 database by using h2.bat file.
> then i opened thehttp://localhost:8082link to open the H2 browser.

Ro

unread,
Aug 11, 2008, 9:30:13 AM8/11/08
to H2 Database

Hi nico,

I have tried with this coding. but my problem is not solved.

Plz help me out vth different idea....

Nico

unread,
Aug 11, 2008, 9:48:49 AM8/11/08
to H2 Database
Well I think the error is a bit different because it should now
complain that the TCP port is already started. This is because
org.h2.console tries to start a server on 9092 and you have already
one running.

What you can try (I tried it it's working for me) is to create a TCP
server which starts the web server :
Server embeddedServer = Server.createTcpServer(new String[] { "-
tcpAllowOthers", "-web" }).start();

Then check that netstatn -an shows port 8092 and 9092 opened and
LISTEN
Then without running h2.bat , go to your web browser and open
http://localhost:8082/
> > > then i opened thehttp://localhost:8082linkto open the H2 browser.

Nico

unread,
Aug 11, 2008, 10:00:05 AM8/11/08
to H2 Database
Hi,

With the example I provided it seems that the web server doesn't
actually starts ...
The following works fine:

Server embeddedServer = new Server();
embeddedServer.run(new String[] { "-tcp", "-web" }, System.out);
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://
localhost/~/test", "sa", "");


On 11 août, 15:48, Nico <nicolas.joua...@gmail.com> wrote:
> Well I think the error is a bit different because it should now
> complain that the TCP port is already started. This is because
> org.h2.console tries to start a server on 9092 and you have already
> one running.
>
> What you can try (I tried it it's working for me) is to create a TCP
> server which starts the web server :
> Server embeddedServer = Server.createTcpServer(new String[] { "-
> tcpAllowOthers", "-web" }).start();
>
> Then check that netstatn -an shows port 8092 and 9092 opened and
> LISTEN
> Then without running h2.bat , go to your web browser and openhttp://localhost:8082/
> > > > then i opened thehttp://localhost:8082linktoopen the H2 browser.

Ro

unread,
Aug 12, 2008, 2:51:49 AM8/12/08
to H2 Database
Hi Nico,
Thank you very much. IT is working very fine. But Is
there any way to know whether web server, ftp server are started or
not? then i can proceed in my code like if web server is not started
then start the web server.

Thank you in advance.....

Nico

unread,
Aug 12, 2008, 3:13:35 AM8/12/08
to H2 Database
Hi,

The server class provides a isRunning() method which can tell you if a
server is running, but I don't really know what checks are really made
here. May be Thomas can answer.
One solution (not the best) to test if the server is running could be
to open a socket connection to the server port and checks for
connection success (the server is running) of failure (the server is
down).

Hope this helps.

Ro

unread,
Aug 12, 2008, 6:46:20 AM8/12/08
to H2 Database
Hi nico,

Can you find out the way how can i use isRunning() method to
solev my problem.
I am trying from so much time but also i am able t find the answer for
this one.
> > Thank you in advance.....- Hide quoted text -
>
> - Show quoted text -

Ro

unread,
Aug 12, 2008, 6:49:57 AM8/12/08
to H2 Database
Sorry typo error. i am not able to find the answer for my problem....
Plz help me out....
> > - Show quoted text -- Hide quoted text -

Ro

unread,
Aug 12, 2008, 9:34:46 AM8/12/08
to H2 Database
Hi Nico,
I got the solution. I am just pating my code. Just look at this.
As per my requiement it is working fine.
Just look at this ocde once and tell me if any problem in this....

Server ftpSrv,webSrv;
if (!(webSrv != null && webSrv.isRunning(false)))
{
System.out.println("Starting Web Server.......");
webSrv = Server.createWebServer(new String[] { "-trace" }).start();
System.out.println("Started Web Server.......");
}
if (!(ftpSrv != null && ftpSrv.isRunning(false)))
{
System.out.println("Starting FTP Server.......");
ftpSrv=Server.createFtpServer(new String[] { "-trace" }).start();
System.out.println("Started FTP Server.......");
}
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa",
"");

Thomas Mueller

unread,
Aug 12, 2008, 9:42:06 PM8/12/08
to h2-da...@googlegroups.com
Hi,

> Just look at this ocde once and tell me if any problem in this....

It looks fine to me.

Regards,
Thomas

rohini kanamarlapudi

unread,
Aug 13, 2008, 1:12:38 AM8/13/08
to h2-da...@googlegroups.com
Thank you very much....

Steven

unread,
Aug 14, 2008, 4:51:48 AM8/14/08
to H2 Database
Hi, i just wonder how to start in the mixed mode, will that mode
affect the performance comparing to the embedded mode? Thanks.

On 8月13日, 下午1時12分, "rohini kanamarlapudi" <rohinik...@gmail.com>
wrote:
> > >> - Show quoted text -- 隱藏被引用文字 -
>
> - 顯示被引用文字 -

Thomas Mueller

unread,
Aug 15, 2008, 1:15:52 AM8/15/08
to h2-da...@googlegroups.com
Hi,

> Hi, i just wonder how to start in the mixed mode, will that mode
> affect the performance comparing to the embedded mode? Thanks.

The embedded connections are as fast as if the database is used in
just the embedded mode, while the remote (client/server) connections
are a bit slower. See also
http://www.h2database.com/html/performance.html (compare H2 Embedded
with H2 Client/Server).

Regards,
Thomas

Ro

unread,
Aug 18, 2008, 1:36:14 AM8/18/08
to H2 Database
Hi,

Can you explain how this code is working.......

Ro

unread,
Aug 18, 2008, 1:41:56 AM8/18/08
to H2 Database

Server ftpSrv,webSrv;
if (!(webSrv != null && webSrv.isRunning(false)))
{
System.out.println("Starting Web Server.......");
webSrv = Server.createWebServer(new String[] { "-
trace" }).start();
System.out.println("Started Web Server.......");
}
if (!(ftpSrv != null && ftpSrv.isRunning(false)))
{
System.out.println("Starting FTP Server.......");
ftpSrv=Server.createFtpServer(new String[] { "-
trace" }).start();
System.out.println("Started FTP Server.......");
}
Connection conn = DriverManager.getConnection("jdbc:h2:~/
test", "sa", "");

Hi,
Thia program is working as per my requirement. but i am not
getting y to start web server and ftp server before connecting to
database. I done some R&D but also not getting the answer. plz help me
out....

On Aug 12, 3:49 pm, Ro <rohinik...@gmail.com> wrote:





On Aug 15, 10:15 am, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> > Hi, i just wonder how to start in the mixed mode, will that mode
> > affect the performance comparing to the embedded mode? Thanks.
>
> The embedded connections are as fast as if  the database is used in
> just the embedded mode, while the remote (client/server) connections
> are a bit slower. See alsohttp://www.h2database.com/html/performance.html(compare H2 Embedded

Ro

unread,
Aug 18, 2008, 5:00:01 AM8/18/08
to H2 Database
Even i did not load the driver class by using class.forName() method.
How it is working properly.
> > are a bit slower. See alsohttp://www.h2database.com/html/performance.html(compareH2 Embedded
> > with H2 Client/Server).
>
> > Regards,
> > Thomas- Hide quoted text -

Steven

unread,
Aug 19, 2008, 8:15:43 PM8/19/08
to H2 Database
Thanks.
1) You meant mixed mode was slower than pure embedded mode or only
slower when remote connection invasion?
2) How to start the mixed mode in web admin? Can you point out the URL
to show how?

Thanks again.

On 8月15日, 下午1時15分, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> > Hi, i just wonder how to start in the mixed mode, will that mode
> > affect the performance comparing to the embedded mode? Thanks.
>
> The embedded connections are as fast as if the database is used in
> just the embedded mode, while the remote (client/server) connections
> are a bit slower. See alsohttp://www.h2database.com/html/performance.html(compare H2 Embedded

Steven

unread,
Oct 13, 2008, 8:46:53 AM10/13/08
to H2 Database
Hi I just wonder if mixed-mode is available for use? Thanks.

On 8月20日, 上午8時15分, Steven <steven.mark.jo...@gmail.com> wrote:
> Thanks.
> 1) You meantmixedmodewas slower than pure embeddedmodeor only
> slower when remote connection invasion?
> 2) How to start themixedmodein web admin? Can you point out the URL
> to show how?
>
> Thanks again.
>
> On 8月15日, 下午1時15分, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
> wrote:
>
>
>
> > Hi,
>
> > > Hi, i just wonder how to start in themixedmode, will thatmode
> > > affect the performance comparing to the embeddedmode? Thanks.
>
> > The embedded connections are as fast as if the database is used in
> > just the embeddedmode, while the remote (client/server) connections
> > are a bit slower. See alsohttp://www.h2database.com/html/performance.html(compareH2 Embedded
> > with H2 Client/Server).
>
> > Regards,
> > Thomas- 隱藏被引用文字 -
>
> - 顯示被引用文字 -

Mike Monkiewicz

unread,
Oct 14, 2008, 9:58:48 AM10/14/08
to H2 Database
It is. I just implemented it on our system. You need to use
v1.1.100 (or later) of H2. If you're like me, and have a embedded
database accessed through JDBC, your URL probably looks like:
jdbc:h2:file:C:/blah/blah. Just append AUTO_SERVER=TRUE to your URL,
and you're good to go:

example:
jdbc:h2:file:C:/blah/blah;AUTO_SERVER=TRUE

Steven

unread,
Oct 15, 2008, 2:11:38 AM10/15/08
to H2 Database
Thanks.Mike. I just dig out how to do this. Actually I found the
example in test.I open a port listening in my application. And now I
can use web tool through jdbc TCP to access the db tables at the same
time(application uses embedded mode to write and read from file). The
weird thing is I never set up AUTO_SERVER=TRUE. Furthermore, I also
doubt if it affects the performance when the port is always listening
in my application.
> > > - 顯示被引用文字 -- 隱藏被引用文字 -
>
> - 顯示被引用文字 -

Steven

unread,
Oct 15, 2008, 2:14:56 AM10/15/08
to H2 Database
I just found out i am useing 1.0.71 version.How could mixed mode work?

Steven

unread,
Oct 15, 2008, 5:41:23 AM10/15/08
to H2 Database
Hi I tried your method and it worked, is that so called "mixed-mode"?
Or just the new way to access the embedded mode from another process
since "mixed mode" means server mode + embedded mode?

On 10月14日, 下午9時58分, Mike Monkiewicz <monkiew...@gmail.com> wrote:
> > > - 顯示被引用文字 -- 隱藏被引用文字 -
>
> - 顯示被引用文字 -

Thomas Mueller

unread,
Oct 15, 2008, 3:04:38 PM10/15/08
to h2-da...@googlegroups.com
Hi,

> if it affects the performance when the port is always listening in my application.

No, it doesn't affect performance.

> 1.0.71 version.How could mixed mode work?

'Mixed mode' can mean two things. One is: start a server manually and
then connect to it. See also
http://www.h2database.com/html/features.html#connection_modes - this
works since a long time.

The feature AUTO_SERVER is quite new and requires version 1.0.79
(2008-09-26) or newer. If it works with an older version that would be
strange. In fact it should throw an exception, except if you also use
;IGNORE_UNKNOWN_SETTINGS=TRUE (in which case AUTO_SERVER is simply
ignored).

Regards,
Thomas

Steven

unread,
Oct 16, 2008, 2:17:02 AM10/16/08
to H2 Database
Thanks. SET AUTO_SERVER = mixed mode?

On 10月16日, 上午3時04分, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> > if it affects the performance when the port is always listening in my application.
>
> No, it doesn't affect performance.
>
> > 1.0.71 version.How could mixed mode work?
>
> 'Mixed mode' can mean two things. One is: start a server manually and
> then connect to it. See alsohttp://www.h2database.com/html/features.html#connection_modes- this

Thomas Mueller

unread,
Oct 16, 2008, 2:41:01 AM10/16/08
to h2-da...@googlegroups.com
Hi,

> SET AUTO_SERVER = mixed mode?

No. 'Mixed mode' can mean two things:

(A) start a server manually and then connect to it.
(B) AUTO_SERVER=TRUE in which case the server is started automatically.

Regards,
Thomas

Steven

unread,
Oct 16, 2008, 5:02:48 AM10/16/08
to H2 Database
OK.Let me clarify it.

1)Auto_server provides a new access method to embedded mode since in
old embedded mode only one process could possible access the db.
2)Mixed mode means starting a server listening on a port along with a
embedded mode enable, while remote access to the db is
possible.Meanwhile,the embedded mode still working as fast as without
server listening.

Am I correct?

On Oct 16, 3:04 am, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>
> > if it affects the performance when the port is always listening in my application.
>
> No, it doesn't affect performance.
>
> > 1.0.71 version.How could mixed mode work?
>
> 'Mixed mode' can mean two things. One is: start a server manually and
> then connect to it. See alsohttp://www.h2database.com/html/features.html#connection_modes- this

Thomas Mueller

unread,
Oct 18, 2008, 5:06:50 AM10/18/08
to h2-da...@googlegroups.com
Hi,

> 1)Auto_server provides a new access method to embedded mode since in
> old embedded mode only one process could possible access the db.

> 2)Mixed mode means starting a server listening on a port along with a
> embedded mode enable, while remote access to the db is
> possible.Meanwhile,the embedded mode still working as fast as without
> server listening.

Actually Auto_server is also a mixed mode. 'Mixed mode' can mean two things:

(A) start a server manually and then connect to it.
(B) AUTO_SERVER=TRUE in which case the server is started automatically.

Mixed mode only means: "one application used the database in embedded
mode, while another in server mode, at the same time".

There are two ways to start the server: one is manually using the API
at http://www.h2database.com/javadoc/org/h2/tools/Server.html - the
other way to start the server (if it is not already running) is by
appending ;AUTO_SERVER=TRUE to the database URL.

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages