primer commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>fichero_02_01</groupId>
|
||||||
|
<artifactId>fichero_02_01</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>26.10.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>18</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -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
|
||||||
|
+ "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Coche> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Java-Version: 18
|
||||||
|
Build-Jdk-Spec: 25
|
||||||
|
Created-By: Maven Integration for Eclipse
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>fichero_02_01</groupId>
|
||||||
|
<artifactId>fichero_02_01</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>26.10.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>18</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user