Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: Function eregi_replace() is deprecated in /home/jcmouse/public_html/app/code/include/model/database/posts.php on line 322

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18
Conexion java + postgres - Code Army!
APUNTES SCHOOL/UNIV | Hace 13 años          

Conexion java + postgres


Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/jcmouse/public_html/app/code/include/model/database/db.class.php on line 18

El programa muestra la conexión JAVA - Postgres mostrando los resultados de una consulta en la consola de JAVA.

Para hacer correr el programa debe de considerar los siguientes puntos.
1. Cree su propia base de datos y adaptela en la clase principal.

clase main

  1. package principal;
  2.  
  3. import conexionBD.Conexion;
  4.  
  5. public class Main {
  6.  
  7. /**
  8.   * @param args the command line arguments
  9.   */
  10. public static void main(String[] args) {
  11. // TODO code application logic here
  12. if(Conexion.conectarBD("dbElecciones","postgres","sis306", "localhost","postgresql"))
  13. {
  14. System.out.println("Se Conecto a la BD");
  15. Cliente cli = new Cliente();
  16. cli.obtenerDatos();
  17.  
  18. }else
  19. System.out.println("No se Pudo Conectar a la BD");
  20. }
  21.  
  22. }
  23.  

clase cliente

  1. package principal;
  2.  
  3. import java.sql.SQLException;
  4. import java.sql.ResultSet;
  5.  
  6. import conexionBD.ConsultaBD;
  7.  
  8. public class Cliente {
  9. private ResultSet res;
  10. private ConsultaBD consul;
  11. private String sql;
  12.  
  13. /** Creates a new instance of Principal */
  14. public Cliente() {
  15. consul = new ConsultaBD();
  16.  
  17. }
  18.  
  19. /**
  20.   * @param args the command line arguments
  21.   */
  22. public void obtenerDatos() {
  23. sql ="select * from candidato";
  24. res= consul.consultar(sql);
  25. try{
  26.  
  27. while(res.next())
  28. {
  29. System.out.println("CI_C : "+res.getString(1));
  30. System.out.println("CD_C: "+res.getString(2));
  31. System.out.println("Nombre: "+res.getString(3));
  32. System.out.println("Apellidos : "+res.getString(4));
  33. System.out.println("**************");
  34.  
  35. }
  36. System.out.println("Se recorio ya todos los datos!!!");
  37. }catch(SQLException sqle)
  38. {
  39. System.out.println("Exeption :"+sqle.getMessage());
  40. System.out.println("Estado del SQL:"+sqle.getSQLState());
  41. System.out.println("Error de Proveedor: "+sqle.getErrorCode());
  42.  
  43. }
  44. }
  45. }

Tags
Fuentes de Información
  • El contenido del post es de mi autoría, y/o, es un recopilación de distintas fuentes.
Dar Puntos
Quitar Puntos
 
10 Puntos
score +10/-0
5145
Visitas
Scrum en 5 m
Apuntes School/Univ
Ordenar digi
Apuntes School/Univ
Clase Emplea
Apuntes School/Univ
Comentarios
yachaywasi
Capitan
 
 Bolivia
Pais
 
 574
Puntos
 
 65
Posts
 
 4
Preguntas
 
 0
Respuestas
 
 Hombre
Sexo
X

Se parte de Code Army!

Esta acción es solo para usuarios registrados