From ec312b91e863d19ce847ca8da8d4d8500bb89a8c Mon Sep 17 00:00:00 2001 From: alumnoT Date: Tue, 27 Oct 2026 17:39:59 +0100 Subject: [PATCH] 1 --- .gitignore | 4 + pom.xml | 27 +++++ src/scripts/Coche.java | 26 +++++ src/scripts/Main.java | 96 ++++++++++++++++++ target/classes/META-INF/MANIFEST.MF | 5 + .../Conectores_01/pom.properties | 7 ++ .../maven/Conectores_01/Conectores_01/pom.xml | 27 +++++ target/classes/scripts/Coche.class | Bin 0 -> 1444 bytes target/classes/scripts/Main.class | Bin 0 -> 5115 bytes 9 files changed, 192 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/scripts/Coche.java create mode 100644 src/scripts/Main.java create mode 100644 target/classes/META-INF/MANIFEST.MF create mode 100644 target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.properties create mode 100644 target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.xml create mode 100644 target/classes/scripts/Coche.class create mode 100644 target/classes/scripts/Main.class diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04d1370 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.settings/ +bin/ +.classpath +.project \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..31f2b4d --- /dev/null +++ b/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + Conectores_01 + Conectores_01 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 26.10.0 + compile + + + + src + + + maven-compiler-plugin + 3.13.0 + + 26 + + + + + \ No newline at end of file diff --git a/src/scripts/Coche.java b/src/scripts/Coche.java new file mode 100644 index 0000000..222bd37 --- /dev/null +++ b/src/scripts/Coche.java @@ -0,0 +1,26 @@ +package scripts; + +public class Coche { + private int codigo; + private String marca; + private String modelo; + private double precio; + + public Coche(int codigo, String marca, String modelo, double precio) { + this.codigo = codigo; + this.marca = marca; + this.modelo = modelo; + this.precio = precio; + } + + // Getters + public int getCodigo() { return codigo; } + public String getMarca() { return marca; } + public String getModelo() { return modelo; } + public double getPrecio() { return precio; } + + @Override + public String toString() { + return "Coche [Código=" + codigo + ", Marca=" + marca + ", Modelo=" + modelo + ", Precio=" + precio + "]"; + } +} diff --git a/src/scripts/Main.java b/src/scripts/Main.java new file mode 100644 index 0000000..717838e --- /dev/null +++ b/src/scripts/Main.java @@ -0,0 +1,96 @@ +package scripts; +//10.100.11.138 +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + public static void main(String[] args) throws Exception { + // 1. Datos de conexión directos (¡Recuerda cambiar localhost por la IP de tu M.V. si ejecutas desde fuera!) + String url = "jdbc:mysql://10.100.11.138:3306/concesionario?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"; + String user = "root"; + String pass = "1234"; // Cambia por tu contraseña de la M.V. + + // Conectar a la base de datos + Connection conexion = DriverManager.getConnection(url, user, pass); + Statement stmt = conexion.createStatement(); + System.out.println("=== Conectado a MySQL ===\n"); + + // ----------------------------------------------------------------- + // A. CONSULTAR LA LISTA DE COCHES E IMPRIMIRLOS + // ----------------------------------------------------------------- + ResultSet rs = stmt.executeQuery("SELECT * FROM T_COCHE"); + List listaCodigosIniciales = new ArrayList<>(); + + System.out.println("--- 1. Consultando coches de T_COCHE ---"); + while (rs.next()) { + int id = rs.getInt("identificador"); + String marca = rs.getString("marca"); + String modelo = rs.getString("modelo"); + double cilindrada = rs.getDouble("cilindrada"); + + System.out.println("Coche -> ID: " + id + " | " + marca + " " + modelo + " | Cilindrada: " + cilindrada); + + // Guardamos los identificadores en la lista para el borrado + listaCodigosIniciales.add(id); + } + rs.close(); + + // ----------------------------------------------------------------- + // B. BORRAR MEDIANTE LA LISTA DE COCHES + // ----------------------------------------------------------------- + System.out.println("\n--- 2. Borrando coches mediante la lista ---"); + PreparedStatement psDelete = conexion.prepareStatement("DELETE FROM T_COCHE WHERE identificador = ?"); + for (int id : listaCodigosIniciales) { + psDelete.setInt(1, id); + psDelete.executeUpdate(); + System.out.println("Borrado ID: " + id); + } + psDelete.close(); + + // ----------------------------------------------------------------- + // C. RE-INSERTAR LOS COCHES DESDE LA LISTA INICIAL (Tu SQL Exacto) + // ----------------------------------------------------------------- + System.out.println("\n--- 3. Reinsertando coches iniciales ---"); + PreparedStatement psInsert = conexion.prepareStatement("INSERT INTO T_COCHE (identificador, marca, modelo, cilindrada) VALUES (?, ?, ?, ?)"); + + // Array con tus datos exactos para insertarlos limpiamente en un bucle corto + Object[][] datosCoches = { + {1, "Renault", "Megane", 1.5}, + {2, "Seat", "León", 1.6}, + {3, "Suzuki", "Vitara", 1.9}, + {4, "Seat", "Clio", 1.4}, + {5, "Seat", "Ibiza", 1.4}, // Este volverá a su estado inicial antes del update + {6, "Peugeot", "308", 2.0}, + {7, "Renault", "Megane", 1.5} + }; + + for (Object[] coche : datosCoches) { + psInsert.setInt(1, (int) coche[0]); + psInsert.setString(2, (String) coche[1]); + psInsert.setString(3, (String) coche[2]); + psInsert.setDouble(4, (double) coche[3]); + psInsert.executeUpdate(); + System.out.println("Reinsertado ID: " + coche[0] + " (" + coche[2] + ")"); + } + psInsert.close(); + + // ----------------------------------------------------------------- + // D. ACTUALIZAR EL COCHE CON CÓDIGO 5 A "Ibiza Eco" + // ----------------------------------------------------------------- + System.out.println("\n--- 4. Actualizando coche con identificador 5 ---"); + PreparedStatement psUpdate = conexion.prepareStatement("UPDATE T_COCHE SET modelo = ? WHERE identificador = ?"); + psUpdate.setString(1, "Ibiza Eco"); + psUpdate.setInt(2, 5); + + int filas = psUpdate.executeUpdate(); + System.out.println("Filas actualizadas: " + filas + " (Modelo del ID 5 cambiado a 'Ibiza Eco')"); + psUpdate.close(); + + // Cerrar recursos globales + stmt.close(); + conexion.close(); + System.out.println("\n=== Procesos CRUD finalizados con éxito ==="); + } +} \ 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..802a2c6 --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Java-Version: 26 +Build-Jdk-Spec: 25 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.properties b/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.properties new file mode 100644 index 0000000..4162cb7 --- /dev/null +++ b/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Tue Oct 27 17:23:44 CET 2026 +artifactId=Conectores_01 +groupId=Conectores_01 +m2e.projectLocation=C\:\\Users\\alumnoT\\eclipse-workspace\\Conectores_01 +m2e.projectName=Conectores_01 +version=0.0.1-SNAPSHOT diff --git a/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.xml b/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.xml new file mode 100644 index 0000000..31f2b4d --- /dev/null +++ b/target/classes/META-INF/maven/Conectores_01/Conectores_01/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + Conectores_01 + Conectores_01 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 26.10.0 + compile + + + + src + + + maven-compiler-plugin + 3.13.0 + + 26 + + + + + \ No newline at end of file diff --git a/target/classes/scripts/Coche.class b/target/classes/scripts/Coche.class new file mode 100644 index 0000000000000000000000000000000000000000..e1d0ad1de4220dea17f2b856e5eb004212b2b589 GIT binary patch literal 1444 zcma)5TTc@~7(LUL-dF@mtp&WGg0>Z?7raq1#u6e4s0jogh!4Yd(k^Uwo85tgH-Cmd z!bFWWCOr7!n?K6<&FltByD>g&=gjn+`ObHl-+xYi0$4*Wg&4z#Z+cco`qjE?wnPdE zhOvEq#H%)Un$Xf4f+%`}`nT)sjfvCHV$>lpswg~x>JCZCd z|8K3LoMgA$L(ddzmP$OUo4csmMeTj*y3&^(?`#U$avOdYi@2LYm0|X*p_X&x9*An- zH?X(HP3d~a%J)5nkENclAv?J66?Yo8@Mkw%_u#No>!F2H(sOc7xP9Ca5%k?2elU== z-r|Q>)VXbMSyI$SlUPV&iD6M^J+oW?^-Xngh0V|C?rET#q)^bJ751LNSa%%Z)ot$k z!cXBb!`whYqEbxZDZ|x&Q|S!^^}uzS);JA70x>nlgkoxl^-3eGR~leilf*PILcbSi z_kmQ3JyrRE(aLlexypPO`N~2Ug-S8eMe(cFPAQINW++CMp2aZf4NTBYlZ2+}|0Rm7 zSeJ2yR)v%krjhaz(@42dPN&p^qPr+bTnpV)X;u88%6H^G5r`2jundgrAVxq4gD}kK z)Kx0I;{2CBaV}DPBT`)G7f(crZ({b;cI?!4@pE6~e582pH1Z3olFGTDa;7g&pTflx n+yeTo6nkzfghhy>qGR5{JgsTE?LK`E@Q`*{LXYqS%b5HNN3bPw literal 0 HcmV?d00001 diff --git a/target/classes/scripts/Main.class b/target/classes/scripts/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..1dbc87de3f9ce6531acf3610509e7427607cfa81 GIT binary patch literal 5115 zcma)A33yyp75?wb%)B=9m3g$Z@Kr} zbIv`>f6mRLuOE5(6@oha2nfvSw$s+e{MfLS={JW{mO!N2NtmetGh@s5;-D|L z!_ErK?yi*CN`7OMEwG?wYxkt=crIh7M_Q%4P}lB+HJ-DbbXG+~;Dkx4@{ET00y}pm zhZ8Mh6WPmCEe#Eg%j+AL^VeA4xMEeyiWSS78xl@BVP(mPiaG81tQC)Uw{165S!=PG zN;y|-$`7aP#0G1k&!Tv1mziqIW%AbItd-ftz1d^d9w%+JZRzjOuz-qZ94DvYBtA7Z ztvDxyg*ZjU$=r&oA=PN;%-CGnW2Vg!E2HC7oF*`9#L9Iz=`?LiRRnr!rtkZWjMREW zQp_Z~)-Vj5sp5>1ou*FfcoP=UV~LDq=B#**moY0%A1|n>U{@Y*4Pr5BR4kbi7x9TK zm+7d**^CJ%&*jygF1FLKiGIt`dzLxYs$rSH!nU?Hg9>uHX3{ZCqh}(%x!d4qD1>?} zSJ6Hyh)g#kt{d=F2gnk6!SW7^=_9z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