import java.sql.*;

public class PGTest {

	public static void main(String args[]) throws Exception {

		Class.forName("org.postgresql.Driver");

		String url = "jdbc:postgresql://192.168.1.102:5432/ziclix";
		Connection conn = null;

		try {
			conn = DriverManager.getConnection(url, "jython", "jython");

			DatabaseMetaData dmd = conn.getMetaData();
			String[] types = new String[]{ "TABLE", "table" };

			for (int i = 0; i < types.length; i++) {
				try {
					System.out.println("");
					System.out.println("Attempting type [" + types[i] + "]");
					getTables(dmd, types[i]);
					System.out.println("SUCCESS with type [" + types[i] + "]");
				} catch (Exception e) {
					System.out.println(" " + e.getMessage());
					System.out.println("FAILURE with type [" + types[i] + "]");
				}
			}
		} finally {
			try {
				conn.close();
			} catch (Throwable t) {}
		}
	}

	private static void getTables(DatabaseMetaData dmd, String type) throws Exception {

		ResultSet rs = null;

		try {
			rs = dmd.getTables(null, null, null, new String[]{ type });

			while ((rs != null) && rs.next()) {
				System.out.println(" table: " + rs.getString(3));
			}
		} finally {
			try {
				rs.close();
			} catch (Throwable t) {}
		}
	}
}
