> 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
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");
}
}
> 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