private static Connection connect ( final String url , final String user , final String password ) throws NamingException , SQLException { if ( url . toLowerCase ( Locale . ROOT ) . startsWith ( "java:" ) ) { DataSource source = ( DataSource ) new InitialContext ( ) . lookup ( url ) ; if ( user == null ) { return source . getConnection ( ) ; } else { return source . getConnection ( user , password ) ; } } else { if ( user == null ) { return DriverManager . getConnection ( url ) ; } else { return DriverManager . getConnection ( url , user , password ) ; } } }
Establishes the connection to the database .