first commit
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
.settings/
|
||||
bin/
|
||||
target/
|
||||
.classpath
|
||||
.project
|
||||
*.class
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
CREATE DATABASE Mapa_Mundi;
|
||||
USE Mapa_Mundi;
|
||||
|
||||
-- Eliminar tablas
|
||||
DROP TABLE IF exists T_PAIS;
|
||||
DROP TABLE IF exists T_CONTINENTE;
|
||||
|
||||
-- DDL de T_CONTINENTE
|
||||
CREATE table IF not exists T_CONTINENTE (
|
||||
codigo char(2),
|
||||
nombre_continente varchar(30),
|
||||
PRIMARY KEY (codigo)
|
||||
);
|
||||
|
||||
-- DDL de T_PAIS
|
||||
CREATE TABLE IF not exists T_PAIS (
|
||||
cod_continente char(2),
|
||||
identificador int auto_increment,
|
||||
nombre_pais varchar(50),
|
||||
capital varchar(20),
|
||||
PRIMARY KEY (identificador),
|
||||
CONSTRAINT FK_PAIS_CONTINENTE
|
||||
FOREIGN KEY (cod_continente) REFERENCES T_CONTINENTE(codigo)
|
||||
);
|
||||
|
||||
-- Información de Continentes
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES ("01","África");
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES ("02","América");
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES ("03","Asia");
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES ("04","Europa");
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente) VALUES ("05","Oceanía");
|
||||
|
||||
-- Información de Paises
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",1, "Angola", "Luanda");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",2, "Argelia", "Argel");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",3, "Benin", "Porto-Novo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",4, "Botsuana", "Gaberones");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",5, "Burkina Faso", "Uagadugú");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",6, "Burundi", "Buyumbura");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",7, "Cabo Verde", "Praia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",8, "Camerún", "Yaundé");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",9, "Chad", "Yamena");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",10, "Comoras", "Moroni");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",11, "Costa De Marfil", "Yamusukro, Abiyán");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",12, "Egipto", "El Cairo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",13, "Eritrea", "Asmara");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",14, "Etiopía", "Adís Abeba");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",15, "Gabón", "Libreville");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",16, "Gambia", "Banjul");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",17, "Ghana", "Accra");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",18, "Guinea", "Conakry");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",19, "Guinea Ecuatorial", "Malabo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",20, "Guinea-Bissau", "Bissau");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",21, "Kenia", "Nairobi");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",22, "Lesoto", "Maseru");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",23, "Liberia", "Monrovia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",24, "Libia", "Trípoli");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",25, "Madagascar", "Antananarivo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",26, "Malaui", "Lilongüe");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",27, "Mali", "Bamako");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",28, "Marruecos", "Rabat");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",29, "Mauricio", "Port Louis");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",30, "Mauritania", "Nuakchot");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",31, "Mozambique", "Maputo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",32, "Namibia", "Windhoek");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",33, "Níger", "Niamey");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",34, "Nigeria", "Abuya");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",35, "República Centroafricana", "Bangui");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",36, "República Del Congo", "Brazzaville");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",37, "República Democrática Del Congo", "Kinshasa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",38, "República Saharaui", "El Aaiún");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",39, "Ruanda", "Kigali");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",40, "Santo Tomé Y Príncipe", "Santo Tomé");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",41, "Senegal", "Dakar");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",42, "Seychelles", "Victoria");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",43, "Sierra Leona", "Freetown");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",44, "Somalia", "Mogadiscio");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",45, "Suazilandia", "Mbabane");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",46, "Sudáfrica","Pretoria");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",47, "Sudán Del Norte", "Jartum");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",48, "Sudán Del Sur", "Yuba");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",49, "Tanzania", "Dodoma");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",50, "Togo", "Lomé");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",51, "Túnez", "Túnez");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",52, "Uganda", "Kampala");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",53, "Yibuti", "Yibuti");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",54, "Zambia", "Lusaka");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("01",55, "Zimbabue", "Harare");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",56, "Antigua Y Barbuda", "Saint John's");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",57, "Argentina", "Buenos Aires");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",58, "Bahamas", "Nassau");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",59, "Barbados", "Bridgetown");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",60, "Belice", "Belmopán");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",61, "Bolivia", "Sucre, La Paz");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",62, "Brasil", "Brasilia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",63, "Canadá", "Ottawa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",64, "Chile", "Santiago De Chile");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",65, "Colombia", "Bogotá");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",66, "Costa Rica", "San José");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",67, "Cuba", "La Habana");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",68, "Dominica", "Roseau");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",69, "Ecuador", "Quito");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",70, "El Salvador", "San Salvador");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",71, "Estados Unidos de América", "Washington D. C.");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",72, "Granada", "Saint George's");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",73, "Guatemala", "Ciudad De Guatemala");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",74, "Guyana", "Georgetown");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",75, "Haití", "Puerto Príncipe");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",76, "Honduras", "Tegucigalpa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",77, "Jamaica", "Kingston");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",78, "México", "México D. F.");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",79, "Nicaragua", "Managua");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",80, "Panamá", "Ciudad De Panamá");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",81, "Paraguay", "Asunción");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",82, "Perú", "Lima");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",83, "Puerto Rico", "San Juan");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",84, "República Dominicana", "Santo Domingo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",85, "San Cristóbal Y Nieves", "Basseterre");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",86, "San Vicente Y Las Granadinas", "Kingstown");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",87, "Santa Lucía", "Castries");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",88, "Surinam", "Paramaribo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",89, "Trinidad Y Tobago", "Puerto España");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",90, "Uruguay", "Montevideo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("02",91, "Venezuela", "Caracas");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",92, "Afganistán", "Kabul");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",93, "Arabia Saudita", "Riad");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",94, "Bangladés", "Daca");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",95, "Baréin", "Manamá");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",96, "Brunei", "Bandar Seri Begawan");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",97, "Bután", "Timbu");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",98, "Camboya", "Pnon Pehn");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",99, "Catar", "Doha");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",100, "China", "Pekín");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",101, "Chipre", "Nicosia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",102, "Corea Del Norte", "Pyongyang");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",103, "Corea Del Sur", "Seúl");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",104, "Emiratos Arabes Unidos", "Abu Dabi");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",105, "Filipinas", "Manila");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",106, "India", "Nueva Delhi");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",107, "Indonesia", "Yakarta");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",108, "Irán", "Teherán");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",109, "Iraq", "Bagdad");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",110, "Israel", "Jerusalén");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",111, "Japón", "Tokio");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",112, "Jordania", "Ammán");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",113, "Kazajistán", "Astaná");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",114, "Kirguistán", "Biskek");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",115, "Kuwait", "Ciudad De Kuwait");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",116, "Laos", "Vientián");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",117, "Líbano", "Beirut");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",118, "Malasia","Kuala Lumpur");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",119, "Maldivas", "Malé");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",120, "Mongolia", "Ulan Bator");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",121, "Myanmar (Birmania)", "Naypyidaw");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",122, "Nepal", "Katmandú");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",123, "Omán", "Mascate");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",124, "Pakistán", "Islamabad");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",125, "Palestina", "Ramala");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",126, "Singapur", "Singapur");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",127, "Siria", "Damasco");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",128, "Sri Lanka", "Colombo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",129, "Tailandia", "Bangkok");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",130, "Taiwan", "Taipeh");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",131, "Tayikistán", "Dusambé");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",132, "Timor Oriental", "Dili");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",133, "Turkmenistán", "Asjabad");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",134, "Turquía", "Ankara");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",135, "Uzbekistán", "Tashkent");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",136, "Vietnam", "Hanoi");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("03",137, "Yemen", "Saná");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",138, "Albania", "Tirana");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",139, "Alemania", "Berlín");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",140, "Andorra", "Andorra La Vieja");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",141, "Armenia", "Ereván");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",142, "Austria", "Viena");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",143, "Azerbaiyán", "Bakú");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",144, "Bélgica", "Bruselas");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",145, "Bielorrusia", "Minsk");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",146, "Bosnia Y Herzegovina", "Sarajevo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",147, "Bulgaria", "Sofía");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",148, "Croacia", "Zagreb");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",149, "Dinamarca", "Copenhague");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",150, "Eslovaquia", "Bratislava");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",151, "Eslovenia", "Lublijana");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",152, "España", "Madrid");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",153, "Estonia", "Tallín");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",154, "Finlandia", "Helsinki");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",155, "Francia", "París");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",156, "Georgia", "Tiflis");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",157, "Grecia", "Atenas");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",158, "Hungría", "Budapest");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",159, "Irlanda", "Dublín");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",160, "Islandia", "Reikiavik");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",161, "Italia", "Roma");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",162, "Letonia", "Riga");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",163, "Liechtenstein", "Vaduz");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",164, "Lituania", "Vilna");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",165, "Luxemburgo", "Luxemburgo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",166, "Malta", "La Valeta");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",167, "Moldavia", "Chisinau");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",168, "Mónaco", "Mónaco");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",169, "Montenegro", "Podgorica");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",170, "Noruega", "Oslo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",171, "Países Bajos", "Amsterdam");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",172, "Polonia", "Varsovia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",173, "Portugal", "Lisboa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",174, "Reino Unido", "Londres");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",175, "República Checa", "Praga");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",176, "República De Macedonia", "Skopje");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",177, "Rumania", "Bucarest");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",178, "Rusia", "Moscú");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",179, "San Marino", "Ciudad De San Marino");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",180, "Serbia", "Belgrado");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",181, "Suecia", "Estocolmo");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",182, "Suiza", "Berna");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",183, "Ucrania", "Kiev");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("04",184, "Vaticano", "Ciudad Del Vaticano");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",185, "Australia", "Canberra");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",186, "Fiyi", "Suva");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",187, "Islas Marshall", "Majuro");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",188, "Islas Salomón", "Honiara");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",189, "Kiribati", "Tarawa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",190, "Micronesia", "Palikir");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",191, "Nauru", "Yaren");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",192, "Nueva Zelanda", "Wellington");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",193, "Palaos", "Melekeok");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",194, "Papúa Nueva Guinea", "Port Moresby");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",195, "Samoa", "Apia");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",196, "Tonga", "Nuku'alofa");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",197, "Tuvalu", "Funafuti");
|
||||
INSERT INTO T_PAIS(cod_continente, identificador, nombre_pais ,capital) VALUES ("05",198, "Vanuatu", "Port Vila");
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
# aadd_conect02: Operaciones DML con JDBC y patrón DAO (MySQL)
|
||||
|
||||
## Descripción
|
||||
|
||||
Proyecto en Java que realiza operaciones básicas de manipulación de datos (DML) sobre la tabla `T_PAIS` de la base de datos `Mapa_Mundi`, administrada por MySQL. Se utiliza el API JDBC y el patrón DAO, y todas las sentencias SQL se ejecutan con `Statement` (no se usa `PreparedStatement`).
|
||||
|
||||
Los datos de conexión no están escritos en el código: se leen del fichero `application.properties` a través de la clase `GestorConfiguracion`. La conexión se abre una sola vez en `AppPrincipal` y se inyecta en el DAO por constructor.
|
||||
|
||||
## Estructura del proyecto
|
||||
|
||||
- `aadd_conect02/`
|
||||
- `src/org/palomafp/aadd/dta/`
|
||||
- `AppPrincipal.java`: clase principal que abre la conexión y ejecuta los cinco pasos del enunciado
|
||||
- `model/`
|
||||
- `Pais.java`: clase del modelo (un país)
|
||||
- `dao/`
|
||||
- `IPaisDao.java`: interfaz del DAO
|
||||
- `impl/`
|
||||
- `PaisDaoJdbc.java`: implementación del DAO con JDBC y `Statement`
|
||||
- `gestores/`
|
||||
- `GestorConfiguracion.java`: carga `application.properties` y devuelve la conexión
|
||||
- `config/`
|
||||
- `application.properties`: configuración (datos de conexión a la BBDD)
|
||||
- `MapaMundi.sql`: script de creación de la base de datos
|
||||
- `pom.xml`
|
||||
- `README.md`
|
||||
|
||||
## Base de datos
|
||||
|
||||
El script `MapaMundi.sql` crea la base de datos `Mapa_Mundi` con dos tablas:
|
||||
|
||||
| Tabla | Columnas |
|
||||
|---|---|
|
||||
| `T_CONTINENTE` | `codigo` (PK), `nombre_continente` |
|
||||
| `T_PAIS` | `cod_continente` (FK a `T_CONTINENTE`), `identificador` (PK, autoincremental), `nombre_pais`, `capital` |
|
||||
|
||||
Contiene 5 continentes y 198 países. Ninguna otra tabla referencia a `T_PAIS`, por lo que el borrado de un país no da problemas de clave foránea.
|
||||
|
||||
## Componentes principales
|
||||
|
||||
- **`Pais`**: clase del modelo con los atributos `codContinente`, `identificador`, `nombrePais` y `capital`, sus getters y setters y `toString()`.
|
||||
- **`IPaisDao`**: interfaz que define las operaciones sobre países. La capa de presentación solo conoce esta interfaz.
|
||||
- **`PaisDaoJdbc`**: implementación de `IPaisDao`. Recibe la `Connection` por constructor y la guarda en un atributo `private final`. Cada método crea un `Statement` a partir de esa conexión y lo cierra con `try-with-resources`; la conexión no la cierra el DAO. El `Pais` se rellena directamente con los datos del `ResultSet`. Las `SQLException` se propagan con `throws` a quien llama.
|
||||
- **`GestorConfiguracion`**: clase de utilidad (constructor privado) que carga `application.properties` en un bloque `static` y entrega la `Connection`.
|
||||
- **`AppPrincipal`**: abre la conexión con `try-with-resources`, crea el DAO pasándosela y ejecuta los cinco pasos del enunciado, cada uno en un método privado que recibe el DAO como parámetro. El `main` solo coordina.
|
||||
|
||||
## Configuración
|
||||
|
||||
Fichero `application.properties`:
|
||||
|
||||
```properties
|
||||
# Información relativa a la base de datos
|
||||
sgdb.clase.driver=com.mysql.cj.jdbc.Driver
|
||||
sgdb.conexion.url=jdbc:mysql://192.168.1.62:3306/
|
||||
bbdd.nombre=Mapa_Mundi
|
||||
bbdd.usuario=myuser
|
||||
bbdd.clave=mypass
|
||||
```
|
||||
|
||||
La URL de conexión se forma concatenando `sgdb.conexion.url` y `bbdd.nombre`, es decir, `jdbc:mysql://192.168.1.62:3306/Mapa_Mundi`. Para ejecutar el proyecto en otro equipo hay que cambiar la IP (o usar `localhost`) y las credenciales.
|
||||
|
||||
## Métodos de `GestorConfiguracion`
|
||||
|
||||
| Método | Acción |
|
||||
|---|---|
|
||||
| bloque `static` | Carga `application.properties` desde el classpath. Si no existe o no se puede leer, lanza una `IllegalStateException` |
|
||||
| `getConexion()` | Carga el driver indicado en `sgdb.clase.driver`, monta la URL y devuelve una `Connection` con el usuario y la clave configurados. Quien la recibe es responsable de cerrarla |
|
||||
|
||||
## Métodos de `IPaisDao` / `PaisDaoJdbc`
|
||||
|
||||
| Método | Sentencia SQL | Devuelve |
|
||||
|---|---|---|
|
||||
| `listarTodos()` | `SELECT` de todos los países | `List<Pais>` |
|
||||
| `buscarPorId(int identificador)` | `SELECT ... WHERE identificador = <id>` | `Pais`, o `null` si no existe |
|
||||
| `insertar(Pais pais)` | `INSERT` con los cuatro campos del país | Filas insertadas |
|
||||
| `actualizar(Pais pais)` | `UPDATE` de continente, nombre y capital por identificador | Filas actualizadas |
|
||||
| `borrar(int identificador)` | `DELETE ... WHERE identificador = <id>` | Filas borradas |
|
||||
|
||||
## Métodos de `AppPrincipal`
|
||||
|
||||
| Método | Acción |
|
||||
|---|---|
|
||||
| `main(String[] args)` | Abre la conexión con `try-with-resources`, crea el `PaisDaoJdbc` y ejecuta los cinco pasos en orden. Si el país 152 no existe, termina sin borrar nada. Captura la `SQLException` en un único punto |
|
||||
| `listarPaises(IPaisDao dao)` | Paso 1. Consulta la lista de países y la imprime |
|
||||
| `consultarPais(IPaisDao dao)` | Paso 2. Consulta el país 152, lo imprime y lo devuelve para los pasos 4 y 5 |
|
||||
| `borrarPais(IPaisDao dao)` | Paso 3. Borra el país 152 y comprueba con una consulta que ya no existe |
|
||||
| `insertarPais(IPaisDao dao, Pais pais)` | Paso 4. Inserta el país obtenido en el paso 2 |
|
||||
| `actualizarCapital(IPaisDao dao, Pais pais)` | Paso 5. Cambia la capital a "Capital city" y actualiza el país |
|
||||
|
||||
Los valores `152` y `"Capital city"` están definidos como constantes (`ID_PAIS` y `NUEVA_CAPITAL`).
|
||||
|
||||
## Pasos del programa
|
||||
|
||||
| Paso | Operación | Resultado esperado |
|
||||
|---|---|---|
|
||||
| 1 | Consultar e imprimir la lista de países | 198 países |
|
||||
| 2 | Consultar e imprimir el país 152 | `España`, capital `Madrid`, continente `04` |
|
||||
| 3 | Borrar el país 152 | `Filas borradas: 1` y la consulta posterior devuelve `null` |
|
||||
| 4 | Insertar el país del paso 2 | `Filas insertadas: 1` y la consulta devuelve España con capital `Madrid` |
|
||||
| 5 | Actualizar la capital | `Filas actualizadas: 1` y la consulta devuelve España con capital `Capital city` |
|
||||
|
||||
## Aspectos a tener en cuenta
|
||||
|
||||
- El país insertado en el paso 4 es el mismo objeto `Pais` que se consultó en el paso 2, guardado en memoria antes de borrarlo. Por eso se recupera con el mismo identificador y el mismo continente.
|
||||
- Con `Statement` los valores se concatenan en la sentencia SQL, por lo que un texto con apóstrofo (por ejemplo `Nuku'alofa`) rompería un `INSERT` o un `UPDATE`. Con España no hay problema. Es la limitación que resuelve `PreparedStatement`.
|
||||
- Se utiliza una única conexión para todas las operaciones. El DAO no sabe cómo se crea (inyección por constructor) y no depende de `GestorConfiguracion`, lo que permitiría agrupar varias operaciones en una transacción si fuese necesario. En esta práctica no se usan transacciones: cada sentencia se confirma automáticamente.
|
||||
- Tras la ejecución, España queda en la base de datos con la capital `Capital city`. Para volver al estado original hay que ejecutar de nuevo `MapaMundi.sql`.
|
||||
- La carpeta `config` está configurada como *source folder* en Eclipse, por lo que `application.properties` está en el classpath.
|
||||
|
||||
## Ejecución
|
||||
|
||||
1. Ejecutar `MapaMundi.sql` en un cliente MySQL (por ejemplo DBeaver) para crear la base de datos.
|
||||
2. Crear el usuario con permisos sobre la base de datos:
|
||||
```sql
|
||||
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
|
||||
GRANT ALL PRIVILEGES ON Mapa_Mundi.* TO 'myuser'@'%';
|
||||
FLUSH PRIVILEGES;
|
||||
```
|
||||
3. Ajustar `config/application.properties` a la IP y credenciales del servidor MySQL.
|
||||
4. Ejecutar `AppPrincipal` como aplicación Java.
|
||||
5. Comprobar en la consola la salida de los cinco pasos.
|
||||
@@ -0,0 +1,6 @@
|
||||
# Información relativa a la base de datos
|
||||
sgdb.clase.driver=com.mysql.cj.jdbc.Driver
|
||||
sgdb.conexion.url=jdbc:mysql://192.168.1.62:3306/
|
||||
bbdd.nombre=Mapa_Mundi
|
||||
bbdd.usuario=myuser
|
||||
bbdd.clave=mypass
|
||||
@@ -0,0 +1,30 @@
|
||||
<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>aadd_conect02</groupId>
|
||||
<artifactId>aadd_conect02</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>26</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.palomafp.aadd.dta;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.dao.IPaisDao;
|
||||
import org.palomafp.aadd.dta.dao.impl.PaisDaoJdbc;
|
||||
import org.palomafp.aadd.dta.gestores.GestorConfiguracion;
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public class AppPrincipal {
|
||||
|
||||
private static final int ID_PAIS = 152;
|
||||
private static final String NUEVA_CAPITAL = "Capital city";
|
||||
|
||||
public static void main(String[] args) {
|
||||
try (Connection conexion = GestorConfiguracion.getConexion()) {
|
||||
IPaisDao dao = new PaisDaoJdbc(conexion);
|
||||
|
||||
listarPaises(dao);
|
||||
|
||||
Pais pais = consultarPais(dao);
|
||||
if (pais == null) {
|
||||
System.out.println("No existe el país " + ID_PAIS + ". Fin.");
|
||||
return;
|
||||
}
|
||||
|
||||
borrarPais(dao);
|
||||
insertarPais(dao, pais);
|
||||
actualizarCapital(dao, pais);
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Error de base de datos: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Consultar la lista de países e imprimirla
|
||||
private static void listarPaises(IPaisDao dao) throws SQLException {
|
||||
System.out.println("=== 1. Lista de países ===");
|
||||
List<Pais> paises = dao.listarTodos();
|
||||
for (Pais pais : paises) {
|
||||
System.out.println(pais);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Consultar el país 152 e imprimirlo
|
||||
private static Pais consultarPais(IPaisDao dao) throws SQLException {
|
||||
System.out.println("\n=== 2. País con identificador " + ID_PAIS + " ===");
|
||||
Pais pais = dao.buscarPorId(ID_PAIS);
|
||||
System.out.println(pais);
|
||||
return pais;
|
||||
}
|
||||
|
||||
// 3. Borrar el país
|
||||
private static void borrarPais(IPaisDao dao) throws SQLException {
|
||||
System.out.println("\n=== 3. Borrado ===");
|
||||
System.out.println("Filas borradas: " + dao.borrar(ID_PAIS));
|
||||
System.out.println("Consulta tras borrar: " + dao.buscarPorId(ID_PAIS));
|
||||
}
|
||||
|
||||
// 4. Insertar el país obtenido en el punto 2
|
||||
private static void insertarPais(IPaisDao dao, Pais pais) throws SQLException {
|
||||
System.out.println("\n=== 4. Inserción ===");
|
||||
System.out.println("Filas insertadas: " + dao.insertar(pais));
|
||||
System.out.println("Consulta tras insertar: " + dao.buscarPorId(ID_PAIS));
|
||||
}
|
||||
|
||||
// 5. Actualizar la capital del país
|
||||
private static void actualizarCapital(IPaisDao dao, Pais pais) throws SQLException {
|
||||
System.out.println("\n=== 5. Actualización ===");
|
||||
pais.setCapital(NUEVA_CAPITAL);
|
||||
System.out.println("Filas actualizadas: " + dao.actualizar(pais));
|
||||
System.out.println("Consulta tras actualizar: " + dao.buscarPorId(ID_PAIS));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.palomafp.aadd.dta.dao;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public interface IPaisDao {
|
||||
|
||||
List<Pais> listarTodos() throws SQLException;
|
||||
|
||||
Pais buscarPorId(int identificador) throws SQLException;
|
||||
|
||||
int insertar(Pais pais) throws SQLException;
|
||||
|
||||
int actualizar(Pais pais) throws SQLException;
|
||||
|
||||
int borrar(int identificador) throws SQLException;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.palomafp.aadd.dta.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.palomafp.aadd.dta.dao.IPaisDao;
|
||||
import org.palomafp.aadd.dta.model.Pais;
|
||||
|
||||
public class PaisDaoJdbc implements IPaisDao {
|
||||
|
||||
private final Connection conexion;
|
||||
|
||||
public PaisDaoJdbc(Connection conexion) {
|
||||
this.conexion = conexion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pais> listarTodos() throws SQLException {
|
||||
List<Pais> lista = new ArrayList<>();
|
||||
String sql = "SELECT cod_continente, identificador, nombre_pais, capital FROM T_PAIS";
|
||||
|
||||
try (Statement st = conexion.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
while (rs.next()) {
|
||||
Pais pais = new Pais();
|
||||
pais.setCodContinente(rs.getString("cod_continente"));
|
||||
pais.setIdentificador(rs.getInt("identificador"));
|
||||
pais.setNombrePais(rs.getString("nombre_pais"));
|
||||
pais.setCapital(rs.getString("capital"));
|
||||
lista.add(pais);
|
||||
}
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pais buscarPorId(int identificador) throws SQLException {
|
||||
Pais pais = null;
|
||||
String sql = "SELECT cod_continente, identificador, nombre_pais, capital FROM T_PAIS "
|
||||
+ "WHERE identificador = " + identificador;
|
||||
|
||||
try (Statement st = conexion.createStatement(); ResultSet rs = st.executeQuery(sql)) {
|
||||
if (rs.next()) {
|
||||
pais = new Pais();
|
||||
pais.setCodContinente(rs.getString("cod_continente"));
|
||||
pais.setIdentificador(rs.getInt("identificador"));
|
||||
pais.setNombrePais(rs.getString("nombre_pais"));
|
||||
pais.setCapital(rs.getString("capital"));
|
||||
}
|
||||
}
|
||||
return pais;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertar(Pais pais) throws SQLException {
|
||||
String sql = "INSERT INTO T_PAIS (cod_continente, identificador, nombre_pais, capital) VALUES ('"
|
||||
+ pais.getCodContinente() + "', " + pais.getIdentificador() + ", '" + pais.getNombrePais() + "', '"
|
||||
+ pais.getCapital() + "')";
|
||||
|
||||
try (Statement st = conexion.createStatement()) {
|
||||
return st.executeUpdate(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int actualizar(Pais pais) throws SQLException {
|
||||
String sql = "UPDATE T_PAIS SET cod_continente = '" + pais.getCodContinente() + "', nombre_pais = '"
|
||||
+ pais.getNombrePais() + "', capital = '" + pais.getCapital() + "' WHERE identificador = "
|
||||
+ pais.getIdentificador();
|
||||
|
||||
try (Statement st = conexion.createStatement()) {
|
||||
return st.executeUpdate(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int borrar(int identificador) throws SQLException {
|
||||
String sql = "DELETE FROM T_PAIS WHERE identificador = " + identificador;
|
||||
|
||||
try (Statement st = conexion.createStatement()) {
|
||||
return st.executeUpdate(sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.palomafp.aadd.dta.gestores;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class GestorConfiguracion {
|
||||
|
||||
private static final String CONFIG = "application.properties";
|
||||
private static final Properties PROPS = new Properties();
|
||||
|
||||
static {
|
||||
try (var is = GestorConfiguracion.class.getClassLoader().getResourceAsStream(CONFIG)) {
|
||||
if (is == null) {
|
||||
throw new IllegalStateException("No se encuentra " + CONFIG + " en el classpath");
|
||||
}
|
||||
PROPS.load(is);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("No se pudo leer " + CONFIG, e);
|
||||
}
|
||||
}
|
||||
|
||||
private GestorConfiguracion() {
|
||||
}
|
||||
|
||||
public static Connection getConexion() throws SQLException {
|
||||
try {
|
||||
Class.forName(PROPS.getProperty("sgdb.clase.driver"));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new SQLException("No se encuentra el driver JDBC", e);
|
||||
}
|
||||
|
||||
String url = PROPS.getProperty("sgdb.conexion.url") + PROPS.getProperty("bbdd.nombre");
|
||||
String usuario = PROPS.getProperty("bbdd.usuario");
|
||||
String clave = PROPS.getProperty("bbdd.clave");
|
||||
|
||||
return DriverManager.getConnection(url, usuario, clave);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.palomafp.aadd.dta.model;
|
||||
|
||||
public class Pais {
|
||||
|
||||
private String codContinente;
|
||||
private int identificador;
|
||||
private String nombrePais;
|
||||
private String capital;
|
||||
|
||||
public Pais() {
|
||||
}
|
||||
|
||||
public Pais(String codContinente, int identificador, String nombrePais, String capital) {
|
||||
this.codContinente = codContinente;
|
||||
this.identificador = identificador;
|
||||
this.nombrePais = nombrePais;
|
||||
this.capital = capital;
|
||||
}
|
||||
|
||||
public String getCodContinente() {
|
||||
return codContinente;
|
||||
}
|
||||
|
||||
public void setCodContinente(String codContinente) {
|
||||
this.codContinente = codContinente;
|
||||
}
|
||||
|
||||
public int getIdentificador() {
|
||||
return identificador;
|
||||
}
|
||||
|
||||
public void setIdentificador(int identificador) {
|
||||
this.identificador = identificador;
|
||||
}
|
||||
|
||||
public String getNombrePais() {
|
||||
return nombrePais;
|
||||
}
|
||||
|
||||
public void setNombrePais(String nombrePais) {
|
||||
this.nombrePais = nombrePais;
|
||||
}
|
||||
|
||||
public String getCapital() {
|
||||
return capital;
|
||||
}
|
||||
|
||||
public void setCapital(String capital) {
|
||||
this.capital = capital;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pais [codContinente=" + codContinente + ", identificador=" + identificador + ", nombrePais="
|
||||
+ nombrePais + ", capital=" + capital + "]";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user