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

import java.sql.*;
public class EjemploJDBC {
public static void main(String[] args) {
System.out.println("Obteniendo registros de una tabla....");
System.out.println("\nMATRICULA MARCA MODELO COLOR KM");
try {
Class.forName(Conexion.driver);
Conexion.con=DriverManager.getConnection(Conexion.url+Conexion.db, Conexion.user, Conexion.pass);
try {
Statement st = Conexion.con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM coche");
System.out.println("");
while(res.next()) {
String matricula = res.getString("matricula");
String marca = res.getString("marca");
String modelo = res.getString("modelo");
String color = res.getString("color");
double km=res.getDouble("km");
System.out.println(matricula + "\t\t" + marca + "\t\t" + modelo + "\t\t" + color + "\t\t" + km);
}
}catch (Exception e) {
e.printStackTrace();
}
Conexion.con.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}