commit b7018f65a7c18f698bba0105fdbf85249a5ce4c2 Author: Álvaro Raúl Quezada Valladares Date: Tue Oct 27 17:39:51 2026 +0100 primer commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43e6c06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +bin/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d74bbf5 --- /dev/null +++ b/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + fichero_02_01 + fichero_02_01 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 26.10.0 + compile + + + + src + + + maven-compiler-plugin + 3.13.0 + + 18 + + + + + \ No newline at end of file diff --git a/src/org/palomafp/add/aqv/Coche.java b/src/org/palomafp/add/aqv/Coche.java new file mode 100644 index 0000000..ed49aa6 --- /dev/null +++ b/src/org/palomafp/add/aqv/Coche.java @@ -0,0 +1,37 @@ +package org.palomafp.add.aqv; + +public class Coche { + private int identificador; + private String marca; + private String modelo; + private double cilindrada; + + public Coche(int identificador, String marca, String modelo, double cilindrada) { + this.identificador = identificador; + this.marca = marca; + this.modelo = modelo; + this.cilindrada = cilindrada; + } + + public int getIdentificador() { + return identificador; + } + + public String getMarca() { + return marca; + } + + public String getModelo() { + return modelo; + } + + public double getCilindrada() { + return cilindrada; + } + + @Override + public String toString() { + return "Coche [ID=" + identificador + ", Marca=" + marca + ", Modelo=" + modelo + ", Cilindrada=" + cilindrada + + "]"; + } +} diff --git a/src/org/palomafp/add/aqv/MainCRUD.java b/src/org/palomafp/add/aqv/MainCRUD.java new file mode 100644 index 0000000..3e211af --- /dev/null +++ b/src/org/palomafp/add/aqv/MainCRUD.java @@ -0,0 +1,77 @@ +package org.palomafp.add.aqv; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class MainCRUD { + + private static final String URL = "jdbc:mysql://10.100.11.140/"; + private static final String USER = "root"; + private static final String PASS = "1234"; + + public static void main(String[] args) { + try (Connection conn = DriverManager.getConnection(URL, USER, PASS)) { + + try (Statement st = conn.createStatement()) { + st.executeUpdate("CREATE DATABASE IF NOT EXISTS Mapamundi"); + System.out.println("Base de datos Mapamundi creada/verificada."); + } + + conn.setCatalog("concesionario"); + + List listaCoches = new ArrayList<>(); + String sqlSelect = "SELECT * FROM T_COCHE"; + try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sqlSelect)) { + while (rs.next()) { + Coche c = new Coche(rs.getInt("identificador"), rs.getString("marca"), rs.getString("modelo"), + rs.getDouble("cilindrada")); + listaCoches.add(c); + } + } + System.out.println("\n--- Lista inicial de coches ---"); + listaCoches.forEach(System.out::println); + + String sqlDelete = "DELETE FROM T_COCHE WHERE identificador = ?"; + try (PreparedStatement pstDelete = conn.prepareStatement(sqlDelete)) { + for (Coche c : listaCoches) { + pstDelete.setInt(1, c.getIdentificador()); + pstDelete.executeUpdate(); + } + System.out.println("\nCoches borrados iterando la lista obtenida."); + } + + String sqlInsert = "INSERT INTO T_COCHE (identificador, marca, modelo, cilindrada) VALUES (?, ?, ?, ?)"; + try (PreparedStatement pstInsert = conn.prepareStatement(sqlInsert)) { + for (Coche c : listaCoches) { + pstInsert.setInt(1, c.getIdentificador()); + pstInsert.setString(2, c.getMarca()); + pstInsert.setString(3, c.getModelo()); + pstInsert.setDouble(4, c.getCilindrada()); + pstInsert.executeUpdate(); + } + System.out.println("Coches reinsertados a partir de la lista."); + } + + String sqlUpdate = "UPDATE T_COCHE SET modelo = 'Ibiza Eco' WHERE identificador = 5"; + try (Statement st = conn.createStatement()) { + int filas = st.executeUpdate(sqlUpdate); + if (filas > 0) { + System.out.println("\nCoche 5 actualizado a 'Ibiza Eco'."); + } + } + + System.out.println("\n--- Estado final de la tabla ---"); + try (Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(sqlSelect)) { + while (rs.next()) { + System.out.println("ID=" + rs.getInt("identificador") + ", Marca=" + rs.getString("marca") + + ", Modelo=" + rs.getString("modelo") + ", Cilindrada=" + rs.getDouble("cilindrada")); + } + } + + } catch (SQLException e) { + System.err.println("Error de base de datos: " + e.getMessage()); + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..0fd30e7 --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Java-Version: 18 +Build-Jdk-Spec: 25 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.properties b/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.properties new file mode 100644 index 0000000..31c2ba6 --- /dev/null +++ b/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Tue Oct 27 17:23:22 CET 2026 +artifactId=fichero_02_01 +groupId=fichero_02_01 +m2e.projectLocation=C\:\\Users\\alvar\\eclipse-workspace\\fichero_02_01 +m2e.projectName=fichero_02_01 +version=0.0.1-SNAPSHOT diff --git a/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.xml b/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.xml new file mode 100644 index 0000000..d74bbf5 --- /dev/null +++ b/target/classes/META-INF/maven/fichero_02_01/fichero_02_01/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + fichero_02_01 + fichero_02_01 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 26.10.0 + compile + + + + src + + + maven-compiler-plugin + 3.13.0 + + 18 + + + + + \ No newline at end of file diff --git a/target/classes/org/palomafp/add/aqv/Coche.class b/target/classes/org/palomafp/add/aqv/Coche.class new file mode 100644 index 0000000..ffb57c0 Binary files /dev/null and b/target/classes/org/palomafp/add/aqv/Coche.class differ diff --git a/target/classes/org/palomafp/add/aqv/MainCRUD.class b/target/classes/org/palomafp/add/aqv/MainCRUD.class new file mode 100644 index 0000000..3f6216b Binary files /dev/null and b/target/classes/org/palomafp/add/aqv/MainCRUD.class differ