Fix problem with stale jdbc connections

Added ConnectionManager that makes sure there is always a working
java.sql.Connection available.
It checks if the connection works and if not it re-initate a new
one.