package com.eofabrik.testing.jdbc;

import java.sql.*;

public class JDBCTest {

	public static void main(String[] args) {
		System.out.println("Start Test...\n");
		
		//requires postgresql-VERSION.jar on classpath
		try {
			Class.forName("org.postgresql.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String jdbcURL  = "jdbc:postgresql";
		String host     = "localhost";
		String port     = "5432";
		String login    = "acuster";
		String pass     = "hello";
		String db       = "coredb";
		
		String jdbcPgsqlURL = jdbcURL + "://" + host + ":" + port + "/" + db + ":anythinggoes?";
		
		Connection dbConnection = null;
		ResultSet  rs           = null;
		
		DriverManager.setLoginTimeout(1); //what does this actually do? We still hang on no net.
		
    	try{ 
			dbConnection = DriverManager.getConnection(jdbcPgsqlURL, login, pass);
		} catch( SQLException ex ){
			//System.out.println( "Couldn't get connection!" );
			System.out.println(ex.getMessage());
		}
		
		if (null != dbConnection){
			try {
				rs = dbConnection.getMetaData().getCatalogs();
				System.out.println("Catalogs are:");
				while (rs.next()){
					System.out.println("  " + rs.getString(1) );
				}
				System.out.println();
				
				rs = dbConnection.getMetaData().getSchemas();
				System.out.println("Schema are:");
				while (rs.next()){
					System.out.println("  " + rs.getString(1) );
				}
				System.out.println();
				
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		
		System.out.println("\n...End Test.    Have a nice day!");
	}
}
