Use UDP broadcasts on the database servers :) This will allow you to pick up the broadcast on all machines on the local network, and the broadcasts themselves can carry the IP address of the servers. For getting the local IP, use InetAddress ip = InetAddress.getLocalHost();
From http://java.sun.com/j2se/1.4.2/docs/api/java/net/DatagramSocket.html:
UDP broadcasts sends are always enabled on a DatagramSocket
. In order to receive broadcast packets a DatagramSocket
should be bound to the wildcard address. In some implementations, broadcast packets may also be received when a DatagramSocket
is bound to a more specific address.
Example: DatagramSocket s = new DatagramSocket(null); s.bind(new InetSocketAddress(8888));
Which is equivalent to: DatagramSocket s = new DatagramSocket(8888);
Both cases will create a DatagramSocket
able to receive broadcasts on UDP port 8888.
Edit: you could also finger all the IP addresses on the network; use the algorithm at http://www.linglom.com/2007/02/20/how-to-find-subnet-number-ip-addresses-in-the-subnet-in-a-few-seconds/ to work out the subnet IPs, iterate over them, and test each for being a H2 server (try connecting). You might want multiple threads to speed up discovery.