You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

2 years ago
  1. import java.sql.*;
  2. public class EjemploJDBC {
  3. public static void main(String[] args) {
  4. System.out.println("Obteniendo registros de una tabla....");
  5. System.out.println("\nMATRICULA MARCA MODELO COLOR KM");
  6. try {
  7. Class.forName(Conexion.driver);
  8. Conexion.con=DriverManager.getConnection(Conexion.url+Conexion.db, Conexion.user, Conexion.pass);
  9. try {
  10. Statement st = Conexion.con.createStatement();
  11. ResultSet res = st.executeQuery("SELECT * FROM coche");
  12. System.out.println("");
  13. while(res.next()) {
  14. String matricula = res.getString("matricula");
  15. String marca = res.getString("marca");
  16. String modelo = res.getString("modelo");
  17. String color = res.getString("color");
  18. double km=res.getDouble("km");
  19. System.out.println(matricula + "\t\t" + marca + "\t\t" + modelo + "\t\t" + color + "\t\t" + km);
  20. }
  21. }catch (Exception e) {
  22. e.printStackTrace();
  23. }
  24. Conexion.con.close();
  25. }catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }