sábado, 1 de marzo de 2014

Conexion con postgres – java – netbeans Antes de ejecutar el programa se debe incluir la librería PostgresSQLJDBCDriver. package javapostgres; /** * * @author Francisco Villavicencio fvillavi@yahoo.com, www.fvillavi.blogspot.com */ import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; public class JavaPostgres { public static Connection Postgres(){ Connection pgConn = null; try { Class.forName("org.postgresql.Driver"); // usuario: postgres, password: xxxxxxxx pgConn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres","xxxxxxxx"); } catch(ClassNotFoundException e) { System.out.print("Class Not Found : " + e.getMessage()); } catch (SQLException exp) { System.out.print("SQL Exception: " + exp.getMessage()); } return pgConn; } public static void main(String[] args) { Connection con = Postgres (); try { System.out.println(con.getCatalog().toString()); } catch (SQLException e){ System.out.println("SQL Exception: " + e.getMessage()); } } }

No hay comentarios: