I think the dbcp class will try execute that query when a getConnection()called, so that might produce the exception
Yes, it tries to execute it.
But it should not throw an exception when it tries to hand you a bad connection. In stead, it tries to fix the connection.
Maybe your database is not reachable when you try to get your connection. In that case, your connection pool won't be able to get a fresh connection for you.
Why don't you show us your exception?