Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLClassLoader;
- import java.sql.*;
- import java.util.Properties;
- public class PrintPg {
- static String url = "jdbc:postgresql://localhost:5432/postgres";
- static String pgJarPath = "file:/path/to/postgresql-9.4.1208.jar";
- public static void main(String[] args) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, MalformedURLException {
- URLClassLoader child = new URLClassLoader(new URL[] { new URL(pgJarPath) }, PrintPg.class.getClassLoader());
- Class<?> driverClass = Class.forName("org.postgresql.Driver", true, child);
- Driver driver = (Driver) driverClass.newInstance();
- Properties info = new Properties();
- info.setProperty("user", "postgres");
- info.setProperty("password", "postgres");
- Connection c = driver.connect(url, info);
- c.setAutoCommit(true);
- PreparedStatement stmt = c.prepareStatement("SELECT * FROM information_schema.columns");
- ResultSet rs = stmt.executeQuery();
- while (rs.next()) {
- System.out.println(""
- + rs.getString("table_catalog") + "\t"
- + rs.getString("table_schema") + "\t"
- + rs.getString("table_name") + "\t"
- + rs.getString("column_name") + "\t"
- + rs.getLong("ordinal_position")
- );
- }
- rs.close();
- c.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement