private Connection getConnection ( final ICommandLine cl ) throws SQLException , InstantiationException , IllegalAccessException , ClassNotFoundException { String database = DEFAULT_TABLE ; if ( cl . hasOption ( "database" ) ) { database = cl . getOptionValue ( "database" ) ; } String hostname = DEFAULT_HOSTNAME ; if ( cl . hasOption ( "hostname" ) && ! "" . equals ( cl . getOptionValue ( "hostname" ) ) ) { hostname = cl . getOptionValue ( "hostname" ) ; } String port = DEFAULT_PORT ; if ( cl . hasOption ( "port" ) && ! "" . equals ( cl . getOptionValue ( "port" ) ) ) { port = cl . getOptionValue ( "port" ) ; } String password = "" ; if ( cl . hasOption ( "password" ) ) { password = cl . getOptionValue ( "password" ) ; } String username = "" ; if ( cl . hasOption ( "logname" ) ) { username = cl . getOptionValue ( "logname" ) ; } String timeout = DEFAULT_TIMEOUT ; if ( cl . getOptionValue ( "timeout" ) != null ) { timeout = cl . getOptionValue ( "timeout" ) ; } Properties props = new Properties ( ) ; props . setProperty ( "user" , username ) ; props . setProperty ( "password" , password ) ; props . setProperty ( "timeout" , timeout ) ; String url = "jdbc:postgresql://" + hostname + ":" + port + "/" + database ; DriverManager . registerDriver ( ( Driver ) Class . forName ( "org.postgresql.Driver" ) . newInstance ( ) ) ; return DriverManager . getConnection ( url , props ) ; }
Connect to the server .