How can I get the port number for a MIXED MODE startup

956 views
Skip to first unread message

Dave L

unread,
Mar 5, 2009, 4:54:25 PM3/5/09
to H2 Database
Hello:
I can't seem to find this answer anywhere on the net. I am starting
up in mixed mode using:

jdbc.url=jdbc:h2:db/dbname;AUTO_SERVER=TRUE;TRACE_LEVEL_FILE=4

I can not find any log message that tells me where port the server is
running on. The normal web page does not come up either.
I am using H2 version: 1.0.79.

Thanks,

Dave L

Thomas Mueller

unread,
Mar 6, 2009, 1:13:27 AM3/6/09
to h2-da...@googlegroups.com
Hi,

> I am starting up in mixed mode using:
>
> jdbc.url=jdbc:h2:db/dbname;AUTO_SERVER=TRUE;TRACE_LEVEL_FILE=4
>
> I can not find any log message that tells me where port the server is
> running on.

Why do you want to know the port number? The whole point if the mixed
mode is that you don't _need_ to know the port number.

> The normal web page does not come up either.

You wrote "I am starting up in mixed mode". How did you start up? Did
you open a database connection? Why do you expect a web page should
come up?

Regards,
Thomas

Thomas Mueller

unread,
Mar 6, 2009, 1:19:50 AM3/6/09
to h2-da...@googlegroups.com
Hi,

Probably the documentation about the mixed mode is unclear. I will
extend it. Here is what I have so far:

== Mixed Mode ==

"The mixed mode is a combination of the embedded and the remote mode.
The first application that connects to a database does that in
embedded mode, but also starts a server so that other applications
(running in different processes or virtual machines) can concurrently
access the same data. The embedded connections are as fast as if
the database is used in just the embedded mode, while the remote
connections are a bit slower. All clients that want to connect to the
database (no matter if it's an embedded or remote connection) can do
so using the exact same database URL."

Does this answer your questions?

Regards,
Thomas

Dave L

unread,
Mar 6, 2009, 10:42:33 AM3/6/09
to H2 Database
Thomas:
Thanks for the reply. I think I understand now. See below.

On Mar 6, 12:13 am, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

>
> You wrote "I am starting up in mixed mode". How did you start up? Did
> you open a database connection? Why do you expect a web page should
> come up?
>
I am starting up using a jdbc connection url of: jdbc:h2:db/
dbname;AUTO_SERVER=TRUE; in process A on server X.
I want to connect another process in a different JVM to the database
in process A using JDBC so the URL I need to use is:

jdbc:h2:db/dbname;AUTO_SERVER=TRUE;

or

jdbc:h2:db/dbname

per your comments below:

> All clients that want to connect to the
> database (no matter if it's an embedded or remote connection) can do
> so using the exact same database URL."

So, I do not need and can NOT use the URL of the format: "Remote
using TCP/IP jdbc:h2:tcp://<server>[:<port>]/<databaseName> "

Is this correct?

This is why I am asking about the port number. In other words the
Mixed Mode capability only works on the same server, it does not
support remote TCP connections?
If I am wrong, then I would need to know the port number for remote
server applications to allow it to connect.

My goal is to run Mixed Mode (embedded) in process A on server X but
have an application on server Y access the database in process A on
server X.
It this possible? I still want to use the embedded feature because of
the speed.

Thanks,

Dave

Thomas Mueller

unread,
Mar 8, 2009, 8:21:01 AM3/8/09
to h2-da...@googlegroups.com
Hi,

> I am starting up using a jdbc connection url of:  jdbc:h2:db/
> dbname;AUTO_SERVER=TRUE; in process A on server X.
> I want to connect another process in a different JVM to the database
> in process A using JDBC so the URL I need to use is:
>
>   jdbc:h2:db/dbname;AUTO_SERVER=TRUE;
>
> or
>
>  jdbc:h2:db/dbname

You need to use jdbc:h2:db/dbname;AUTO_SERVER=TRUE

> So, I do not need and can NOT  use the URL of the format: "Remote
> using TCP/IP  jdbc:h2:tcp://<server>[:<port>]/<databaseName> "
> Is this correct?

That's correct, you don't need to use the TCP/IP address.

> This is why I am asking about the port number.  In other words the
> Mixed Mode capability only works on the same server, it does not
> support remote TCP connections?

No, the mixed mode also works if you have multiple computers. But in
that case the database files must be accessible from each computer
(for example using NFS, or Windows file sharing).

> My goal is to run Mixed Mode (embedded) in process A on server X but
> have an application on server Y access the database in process A on
> server X.
> It this possible? I still want to use the embedded feature because of
> the speed.

If server Y can access the files on server X then the "Automatic Mixed
Mode" is fine.

If server Y can't access the files, then you can still use the mixed
mode, however it's no longer automatic. See also
http://www.h2database.com/html/features.html#connection_modes "Mixed
Mode":

"The mixed mode is a combination of the embedded and the remote mode.

The main application connects to a database in embedded mode, but also


starts a server so that other applications (running in different

virtual machines) can concurrently access the same data. The embedded
connections are as fast as if the database is used in just the
embedded mode, while the remote connections are a bit slower."

So you start a server in the process where access the database in embedded mode.

Regards,
Thomas

Dave L

unread,
Mar 8, 2009, 10:52:20 AM3/8/09
to H2 Database
Thanks Thomas:

>
> If server Y can't access the files, then you can still use the mixed
> mode, however it's no longer automatic. See alsohttp://www.h2database.com/html/features.html#connection_modes"Mixed
> Mode":
>

This still confuses me, so if server Y cannot access the files on
Server X, then how would a process on server Y connect to the mixed
mode database on server X when it does not know the tcp port number?

In other words, what is the db url of rhe process on server Y (which
can not access the files on server X)?

It sounds like in this case I need to use this form of the url when I
start the mixed mode database on server X.

dbc:h2:tcp://<server>[:<port>]/<databaseName> ;AUTO_SERVER=true.

Thanks,

Thomas Mueller

unread,
Mar 8, 2009, 11:21:54 AM3/8/09
to h2-da...@googlegroups.com
Hi,

There is a difference between "Automatic Mixed Mode" and "Mixed Mode".

> This still confuses me, so if server Y cannot access the files on
> Server X, then how would a process on server Y connect to the mixed
> mode database on server X when it does not know the tcp port number?

In that case, don't use ;AUTO_SERVER=true, and pick your own port.
Here an example of what you need to do:

Process 1:
This process uses the database in embedded mode, and starts a server.
Connection embeddedConnection =
DriverManager.getConnection("jdbc:h2:/data/h2/test", "sa", "sa");
String[] args = new String[] {"-tcpPort", "7123", "-tcpAllowOthers"};
Server server = Server.createTcpServer(args).start();

Process 2:
This process can run on another machine.
Connection remoteConnection =
DriverManager.getConnection("jdbc:h2:tcp://servername:7123/data/h2/test",
"sa", "sa");

See also http://www.h2database.com/html/tutorial.html#using_server

Regards,
Thomas

golgoth14

unread,
Mar 9, 2009, 9:07:33 AM3/9/09
to H2 Database
Hi,

This last post is interesting.
I'm using a connection pool on Glassfish v3 and I would like to start
a H2 server
at the same time of the pool creation.

How to use the parameters "-tcpPort" and "-tpcAllowOthers" in this
case ?

Thank you.
Steve

Thomas Mueller

unread,
Mar 9, 2009, 2:38:28 PM3/9/09
to h2-da...@googlegroups.com
Hi,

> I'm using a connection pool on Glassfish v3 and I would like to start
> a H2 server
> at the same time of the pool creation.
>
> How to use the parameters "-tcpPort" and "-tpcAllowOthers" in this
> case ?

Sorry, what do you mean with 'how to use the parameters'?

Regards,
Thomas

Reply all
Reply to author
Forward
0 new messages