Guest User

Untitled

a guest
Dec 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import java.sql.DriverManager;
  2. import java.sql.ResultSet;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5.  
  6. public class ConeccionJBDC {
  7.  
  8. public static void main(String[] args) throws SQLException{
  9. Connection con = obtConeccion();
  10. if(con != null){
  11. Statement sen = con.createStatement();
  12. ResultSet resultado = sen.executeQuery("Select* from socios");
  13. while(resultado.next()){
  14. System.out.println(resultado.getString("direccion" +
  15. ""));
  16. }
  17. }
  18. }
  19.  
  20. public static Connection obtConeccion(){
  21. Connection R = null;
  22. boolean hayDriver = false;
  23. try {
  24. Class.forName("org.postgresql.Driver");
  25. hayDriver = true;
  26. } catch (ClassNotFoundException e) {
  27. // TODO Auto-generated catch block
  28. e.printStackTrace();
  29. }
  30.  
  31. if(hayDriver){
  32. try {
  33. R = DriverManager.getConnection("jdbc:postgresql://pg-devel.palermo.com.py:5432/pruebas","admin","adminadmin");
  34. } catch (SQLException e) {
  35. // TODO Auto-generated catch block
  36. e.printStackTrace();
  37. }
  38. }
  39.  
  40. return R;
  41. }
  42. }
Add Comment
Please, Sign In to add comment