Using AUTO_SERVER=true

1,799 views
Skip to first unread message

Rabatjes

unread,
Jan 19, 2009, 6:34:44 PM1/19/09
to H2 Database

Hi all,

I'm trying to use the H2 server mixed mode in order to let multiple
applications access
the same database. The connection URL I've come up with so far is as
follows:

jdbc:h2:"local path
here";MODE=MySQL;AUTO_SERVER=TRUE;CIPHER=AES;IFEXISTS=true

When I attempt to connect to an existing database, I get the
connection broken exception.
Is this perhaps because of an invalid combination of url properties?
Or do i need
to include AUTO_SERVER in the initial connection url when creating the
database?

Thanks in advance for any help,

Bart

Thomas Mueller

unread,
Jan 20, 2009, 2:52:06 PM1/20/09
to h2-da...@googlegroups.com
Hi,

> jdbc:h2:"local path
> here";MODE=MySQL;AUTO_SERVER=TRUE;CIPHER=AES;IFEXISTS=true
>
> When I attempt to connect to an existing database, I get the
> connection broken exception.

Could you post the exact URL, and the stack trace including the
complete message?

Maybe this problem is fixed in the newest version. What version do you use?

> Is this perhaps because of an invalid combination of url properties?
> Or do i need
> to include AUTO_SERVER in the initial connection url when creating the
> database?

No, unless this connection is still open.

Regards,
Thomas

Rabatjes

unread,
Jan 26, 2009, 7:53:20 PM1/26/09
to H2 Database
Hi Thomas,

sorry for the delayed response. Here is the full url:

jdbc:h2:C:/Documents and Settings/borriens/Desktop/MMIC_JAVA/data/
testDB/testDB/
testDB;MODE=MySQL;AUTO_SERVER=TRUE;CIPHER=AES;IFEXISTS=true


Stack trace is:


org.h2.jdbc.JdbcSQLException: Connection is broken [90067-106]
at org.h2.message.Message.getSQLException(Message.java:103)
at org.h2.message.Message.getSQLException(Message.java:114)
at org.h2.message.Message.getSQLException(Message.java:77)
at org.h2.message.Message.getSQLException(Message.java:149)
at org.h2.tools.Server.start(Server.java:452)
at org.h2.engine.Database.startServer(Database.java:599)
at org.h2.engine.Database.open(Database.java:488)
at org.h2.engine.Database.<init>(Database.java:210)
at org.h2.engine.Engine.openSession(Engine.java:57)
at org.h2.engine.Engine.openSession(Engine.java:126)
at org.h2.engine.Engine.getSession(Engine.java:109)
at org.h2.engine.SessionFactoryEmbedded.createSession
(SessionFactoryEmbedded.java:17)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer
(SessionRemote.java:251)
at org.h2.engine.SessionRemote.createSession
(SessionRemote.java:229)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
at org.h2.Driver.connect(Driver.java:58)
at java.sql.DriverManager.getConnection(DriverManager.java:
582)
at java.sql.DriverManager.getConnection(DriverManager.java:
185)
at mmic.databases.javadatabase.H2Database.connect
(H2Database.java:613)
at mmic.databases.javadatabase.MMICDatabaseHandler.connect
(MMICDatabaseHandler.java:278)
at mmic.gui.SurveyFrame.test(SurveyFrame.java:3853)
at mmic.gui.SurveyFrame.main(SurveyFrame.java:246)
at mmic.gui.MainFrame.runSurvey(MainFrame.java:204)
at mmic.gui.MainFrame.actionPerformed(MainFrame.java:117)
at javax.swing.AbstractButton.fireActionPerformed
(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed
(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed
(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed
(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick
(BasicMenuItemUI.java:1220)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased
(BasicMenuItemUI.java:1261)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:
3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent
(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:
3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:173)
Connection is broken [90067-106]
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents
(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:
121)
No connection present

Any thoughts?

Cheers,
Bart

Bart Orriens

unread,
Jan 26, 2009, 7:55:25 PM1/26/09
to H2 Database
In follow up,

the version i'm using is 1.0.79 (the last stable version).

I'll try the same with the latest beta version.

Bart Orriens

unread,
Jan 26, 2009, 8:00:41 PM1/26/09
to H2 Database
The latest beta version gives the exact same problem.


Thomas Mueller

unread,
Jan 27, 2009, 3:07:37 PM1/27/09
to h2-da...@googlegroups.com
Hi,

Thanks for your help! From the stack trace it looks like the following
problem occurs:

1) The server starts
2) A TCP/IP listener is started successfully
3) The database tries to connect to this TCP/IP listener (connect to
itself; a loopback)
4) This connection can't be established after many retries

It looks like a networking problem. I will change the exception
message to include more information. Is there anything special in your
network? What operating system do you use, is it running in a virtual
machine (VMWare or something similar)? What happens if you execute
"ping localhost", and "ping 127.0.0.1"?

Regards,
Thomas

Bart Orriens

unread,
Jan 27, 2009, 5:40:34 PM1/27/09
to h2-da...@googlegroups.com
Hi Thomas,

I'm running this on locally a dell laptop, windows XP, no VM. The local host can be reached normally via the browser (I'm running an Apache 2 web server).
I get the error both when connected to the network as well as without any network connection (relying solely on the local host).

Just let me know when the build contains code for more elaborate exception msg, then I'll run it to find out what is causing the problem.

Cheers,
Bart
--
The new is always the old. Everything that's old was once new, and everything that's new will one day be old. The oldest thing of all is the present, because there's never been anything else but the present. No one has ever lived in the past, and no one lives in the future, either.

Thomas Mueller

unread,
Jan 31, 2009, 1:28:17 PM1/31/09
to h2-da...@googlegroups.com
Hi,

Could you compile and run the following test program, and then post the results?

Regards,
Thomas

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Iterator;
import java.util.TreeMap;

public class TestNetwork {
public static void main(String[] a) throws Exception {
for (Iterator it =
new TreeMap(System.getProperties()).
entrySet().iterator();
it.hasNext();) {
System.out.println(it.next());
}
System.out.println();
System.out.println("localhost:" +
InetAddress.getByName("localhost"));
InetAddress[] addresses =
InetAddress.getAllByName("localhost");
for (int i = 0; i < addresses.length; i++) {
System.out.println(i + ":" + addresses[i]);
}
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("getLocalHost:" + localhost);
addresses = InetAddress.getAllByName(
localhost.getHostAddress());
for (int i = 0; i < addresses.length; i++) {
System.out.println(i + ":" + addresses[i]);
}
InetAddress address =
InetAddress.getByName(localhost.getHostAddress());
System.out.println("byName:" + address);
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(0);
} catch (Exception e) {
e.printStackTrace();
serverSocket = new ServerSocket(0);
}
System.out.println(serverSocket);
int port = serverSocket.getLocalPort();
final ServerSocket accept = serverSocket;
new Thread() {
public void run() {
try {
System.out.println("server accepting");
Socket s = accept.accept();
Thread.sleep(100);
System.out.println("server accepted:" +
s);
System.out.println("server read:" +
s.getInputStream().read());
Thread.sleep(200);
s.getOutputStream().write(234);
Thread.sleep(100);
System.out.println("server closing");
s.close();
System.out.println("server done");
} catch (Throwable t) {
t.printStackTrace();
}
}
}.start();
Thread.sleep(1000);
Socket socket = new Socket();
InetSocketAddress socketAddress =
new InetSocketAddress(address, port);
System.out.println("client:" + socketAddress);
try {
socket.connect(socketAddress, 2000);
Thread.sleep(200);
System.out.println("client:" + socket.toString());
socket.getOutputStream().write(123);
Thread.sleep(100);
System.out.println("client read:" +
socket.getInputStream().read());
socket.close();
} catch (Throwable t) {
t.printStackTrace();
}
System.out.println("done");

}

}

Bart Orriens

unread,
Feb 2, 2009, 12:47:02 PM2/2/09
to h2-da...@googlegroups.com
Hi Thomas,

I ran the program. This was the result:


awt.toolkit=sun.awt.windows.WToolkit
file.encoding=Cp1252
file.encoding.pkg=sun.io
file.separator=\
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.awt.printerjob=sun.awt.windows.WPrinterJob
java.class.path=C:\testnetwork\build\classes;C:\testnetwork\src
java.class.version=50.0
java.endorsed.dirs=C:\Program Files\Java\jdk1.6.0_07\jre\lib\endorsed
java.ext.dirs=C:\Program Files\Java\jdk1.6.0_07\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
java.home=C:\Program Files\Java\jdk1.6.0_07\jre
java.io.tmpdir=C:\DOCUME~1\borriens\LOCALS~1\Temp\
java.library.path=C:\Program Files\Java\jdk1.6.0_07\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\MyPrograms\PHP\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\CVSNT\
java.runtime.name=Java(TM) SE Runtime Environment
java.runtime.version=1.6.0_07-b06
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.6
java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.6.0_07
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=10.0-b23
line.separator=

os.arch=x86
os.name=Windows XP
os.version=5.1
path.separator=;
sun.arch.data.model=32
sun.boot.class.path=C:\Program Files\Java\jdk1.6.0_07\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0_07\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0_07\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.6.0_07\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_07\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0_07\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0_07\jre\classes
sun.boot.library.path=C:\Program Files\Java\jdk1.6.0_07\jre\bin
sun.cpu.endian=little
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
sun.desktop=windows
sun.io.unicode.encoding=UnicodeLittle
sun.java.launcher=SUN_STANDARD
sun.jnu.encoding=Cp1252
sun.management.compiler=HotSpot Client Compiler
sun.os.patch.level=Service Pack 3
user.country=US
user.dir=C:\testnetwork
user.home=
user.language=en
user.name=
user.timezone=
user.variant=

localhost:localhost/127.0.0.1
0:localhost/127.0.0.1
getLocalHost:*********/172.16.201.171  (blanked out the computer name here)
0:/172.16.201.171
byName:/172.16.201.171
ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=1473]
server accepting
client:/172.16.201.171:1473
java.net.ConnectException: Connection refused: connect
done
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at testnetwork.Main.main(Main.java:75)


Any thoughts on why this problem occurs? It confirms your earlier thought that the server can run, but not accept client connections.

I ran netstat -a which shows the server is listening. I also tried ports 8000 and 8080 in case of firewalling issues, but no luck either.

Any suggestions on your side?

Thanks in advance,
Cheers,
Bart

Thomas Mueller

unread,
Feb 2, 2009, 1:59:57 PM2/2/09
to h2-da...@googlegroups.com
Hi,

This is strange, I don't know what the reason could be. I have a
similar result (well the IP is different - that's normal) but it works
for me and probably most others.

There is a workaround: set the system property h2.bindAddress to
"localhost" or (probably even better) "127.0.0.1".

java -Dh2.bindAddress=127.0.0.1 -cp h2*.jar org.h2.tools.Console

Could you try that and tell me if it works?

Regards,
Thomas

Bart Orriens

unread,
Feb 2, 2009, 2:12:56 PM2/2/09
to h2-da...@googlegroups.com
Hi Thomas,

I tried the workaround. In the printout I now get:

h2.bindAddress=localhost

but the error remains the same (also with using "127.0.0.1").
When I run the console program, everything seems to be working fine when i select the h2 server. I can run the example queries
and access the database. But running server mode from my java code still fails.

I will run the test program on another laptop and see if the results are different. If so, then it might be something on my development machine.

Cheers,
Bart


Thomas Mueller

unread,
Feb 2, 2009, 3:17:24 PM2/2/09
to h2-da...@googlegroups.com
Hi,

> I tried the workaround. In the printout I now get:
> h2.bindAddress=localhost

The workaround doesn't do anything for the TestNetwork program, it is
only for the H2 Console. In the Console you shouldn't get that output

> When I run the console program, everything seems to be working fine when i
> select the h2 server. I can run the example queries
> and access the database. But running server mode from my java code still
> fails.

Do you start the server in your Java code? If yes then you also need
to set the system property, for example using the command line option
-Dh2.bindAddress as described above, or using
System.setProperty("h2.bindAddress", ...) before loading the
org.h2.Driver class (and before starting the server of course).

Regards,
Thomas

Bart Orriens

unread,
Feb 2, 2009, 4:53:20 PM2/2/09
to h2-da...@googlegroups.com
Hi Thomas,

sorry, my mistake.

I tried the workaround the way you indicated. It works like a charm! Thanks a lot for your help!

Cheers,
Bart

Reply all
Reply to author
Forward
0 new messages