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();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|