On Jan 20, 1:14 am, Ewald <[email protected]> wrote:
> Hi.
>
> I almost always use H2 in server mode, but I prefer to start the
> server in a seperate JVM. That way I run in it in a "pure" server mode
> with all clients accessing the server via the TCP/IP protocol. This
> way I don't need any application open to still have the database open
> and I can connect to it via NetBeans and Squirrel or anything else. It
> has the added advantage that I can restart any part of the system
> (except the DB server) without affecting other users.
>
> I don't know if this helps. On Windows you can even set H2 as a
> background service and on Linux a daemon thread works wonders.
>
> I then use the following code in each application to access the
> database:
>
> try {
> Class.forName("org.h2.Driver");
> conn = DriverManager.getConnection("jdbc:h2:tcp://" +
> ipAddress +
> "//myappfolder/db/myappdatabasename", userName,
> pwdString);
>
> } catch (Exception e) {
> Logger.VLog("Error connecting to the database!",
> "Error connecting to the database : " + e.toString
> () + " (" + ipAddress + ")");
> }
>
> ipAddress, userName, pwdString are all Strings.
> Logger.VLog is an internal visual logger.
>
> Best regards
> Ewald
Thanks for your example. So I created a server application just using
the following lines:
----------------------------------------------------------------------------------
Server server = Server.createTcpServer().start();
System.out.print("Enter any key to stop server: ");
try {
reader.readLine();
server.stop();
}...
----------------------------------------------------------------------------------
This starts the server and stops it when a key is entered.
I then have an application that tries to cnnect to the server using:
----------------------------------------------------------------------------------
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2://localhost/~/
test", "sa", "");
...(do stuff)...
conn.close();
----------------------------------------------------------------------------------
When i launch this app (haveing the server App running already, i get
the follwoing errors:
"
Could not start Server for the DataFeed
Databaseorg.h2.jdbc.JdbcSQLException: Exception opening port
"9092" (port may be in use), cause: "java.net.BindException: Address
already in use: JVM_Bind" [90061-126]
"
and then
"
org.h2.jdbc.JdbcSQLException: Log file error: "\\localhost\~
\test.trace.db", cause: "org.h2.jdbc.JdbcSQLException: Error while
creating file ""\\localhost\~"" [90062-126]" [90034-126]
"
Seems to me that my second app tries to start the server, but
obviously can't since it's already there. What am i doing wrong?
Thanks in advance!!
Ruben
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.