mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
Compare commits
29 Commits
416b2d0e7a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4200da990 | ||
|
|
3ec83f87d6 | ||
|
|
f66e4a5dc0 | ||
|
|
8d3b26bf60 | ||
|
|
3e859f9db9 | ||
|
|
5b3b41dba0 | ||
|
|
263bd4220b | ||
|
|
dc2cbeefbe | ||
|
|
b6b59798dc | ||
|
|
f0c090da0d | ||
|
|
abf5adcfe9 | ||
|
|
8e18fb286b | ||
|
|
fbcc8026ed | ||
|
|
9ec8ab1912 | ||
|
|
7dbbed7984 | ||
|
|
738c42f160 | ||
|
|
d8c4fa5e4b | ||
|
|
c054a8c34b | ||
|
|
037db3e9a8 | ||
|
|
ac7ecde4d4 | ||
|
|
4ce56eecb3 | ||
|
|
3f082aa864 | ||
|
|
8eba8ca7e3 | ||
|
|
1b2b2350f1 | ||
|
|
acb8877882 | ||
|
|
bc80b72094 | ||
|
|
1f7add9db3 | ||
|
|
2fbd405616 | ||
|
|
ed4fa3294a |
15
.classpath
15
.classpath
@@ -6,5 +6,20 @@
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="librerias/Driver_MySQL_Connector_J/mysql-connector-java-8.0.19.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/javax.persistence_2.1.0.v201304241213.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/org.eclipse.persistence.jpa.modelgen_2.5.2.v20140319-9ad6abd.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/jpa/org.eclipse.persistence.jpars_2.5.2.v20140319-9ad6abd.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/com.sun.xml.bind_2.2.0.v201004141950.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.activation_1.1.0.v201108011116.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.mail_1.4.0.v201005080615.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.xml.bind_2.2.0.v201105210648.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/moxy/javax.xml.stream_1.0.1.v201004272200.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/EclipseLink2.5.2/jlib/eclipselink.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/Jackson/jackson-annotations-2.9.0.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/Jackson/jackson-core-2.9.5.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/Jackson/jackson-databind-2.9.5.jar"/>
|
||||
<classpathentry kind="lib" path="librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
141
BBDDs/01_BBDD_GestionVentaDeCoches/cochesConDatos.sql
Normal file
141
BBDDs/01_BBDD_GestionVentaDeCoches/cochesConDatos.sql
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,174 @@
|
||||
CREATE DATABASE IF NOT EXISTS `centroeducativo` /*!40100 DEFAULT CHARACTER SET utf8 */;
|
||||
USE `centroeducativo`;
|
||||
-- MySQL dump 10.13 Distrib 5.6.13, for Win32 (x86)
|
||||
--
|
||||
-- Host: 127.0.0.1 Database: centroeducativo
|
||||
-- ------------------------------------------------------
|
||||
-- Server version 5.6.16-log
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
|
||||
--
|
||||
-- Table structure for table `curso`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `curso`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `curso` (
|
||||
`id` int(11) NOT NULL,
|
||||
`descripcion` varchar(45) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `curso`
|
||||
--
|
||||
|
||||
LOCK TABLES `curso` WRITE;
|
||||
/*!40000 ALTER TABLE `curso` DISABLE KEYS */;
|
||||
INSERT INTO `curso` VALUES (1,'2017-18');
|
||||
/*!40000 ALTER TABLE `curso` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `estudiante`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `estudiante`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `estudiante` (
|
||||
`id` int(11) NOT NULL,
|
||||
`nombre` varchar(150) DEFAULT NULL,
|
||||
`apellido1` varchar(150) DEFAULT NULL,
|
||||
`apellido2` varchar(150) DEFAULT NULL,
|
||||
`dni` varchar(15) DEFAULT NULL,
|
||||
`direccion` varchar(250) DEFAULT NULL,
|
||||
`email` varchar(150) DEFAULT NULL,
|
||||
`telefono` varchar(150) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `estudiante`
|
||||
--
|
||||
|
||||
LOCK TABLES `estudiante` WRITE;
|
||||
/*!40000 ALTER TABLE `estudiante` DISABLE KEYS */;
|
||||
INSERT INTO `estudiante` VALUES (1,'Julio','Mármol','Mármol','14785236A','dir, 21','adsf','654785214'),(2,'Francisco','Fernández','Fernández','52874369B','dir, 24','f@f.com','741258963'),(3,'Miguel','Palacios','Fernández','58963214C','dir, 26','m@m.com','632521478');
|
||||
/*!40000 ALTER TABLE `estudiante` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `materia`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `materia`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `materia` (
|
||||
`id` int(11) NOT NULL,
|
||||
`nombre` varchar(100) DEFAULT NULL,
|
||||
`acronimo` varchar(15) DEFAULT NULL,
|
||||
`curso_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_asignatura_curso1_idx` (`curso_id`),
|
||||
CONSTRAINT `fk_asignatura_curso1` FOREIGN KEY (`curso_id`) REFERENCES `curso` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `materia`
|
||||
--
|
||||
|
||||
LOCK TABLES `materia` WRITE;
|
||||
/*!40000 ALTER TABLE `materia` DISABLE KEYS */;
|
||||
INSERT INTO `materia` VALUES (1,'Programación','PROG',1),(2,'Lenguajes de Marcas y Sistemas de Gestión de la Información','LMSGI',1),(3,'Sistemas Informáticos','SI',1),(4,'Entornos de Desarrollo','EntDes',1),(5,'Bases de Datos','BD',1),(6,'Formación y Orientación Laboral','FOL',1);
|
||||
/*!40000 ALTER TABLE `materia` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `profesor`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `profesor`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `profesor` (
|
||||
`id` int(11) NOT NULL,
|
||||
`nombre` varchar(150) DEFAULT NULL,
|
||||
`apellido1` varchar(150) DEFAULT NULL,
|
||||
`apellido2` varchar(150) DEFAULT NULL,
|
||||
`dni` varchar(15) DEFAULT NULL,
|
||||
`direccion` varchar(250) DEFAULT NULL,
|
||||
`email` varchar(150) DEFAULT NULL,
|
||||
`telefono` varchar(150) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `profesor`
|
||||
--
|
||||
|
||||
LOCK TABLES `profesor` WRITE;
|
||||
/*!40000 ALTER TABLE `profesor` DISABLE KEYS */;
|
||||
INSERT INTO `profesor` VALUES (1,'Rafael Carlos','López','Ruiz','12345678b','Su casa, 34','asdf','sdaf'),(2,'Joaquín','Molinero','Suárez','23456789B','Su casa también, 42','joaquin@joaquin.com','654789322'),(3,'Miguel Ángel','Pérez','Carmona','98765432C','Otra casa, 12','miguel@miguel.com','654147852'),(4,'Alejandro','Fernández','Fernández','47125896D','Allí, 65','alejandro@alejandro.com','658974125'),(5,'Águeda','Cuenca','Cuenca','96325874','Graná, 25','','698521478');
|
||||
/*!40000 ALTER TABLE `profesor` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `valoracionmateria`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `valoracionmateria`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `valoracionmateria` (
|
||||
`id` int(11) NOT NULL,
|
||||
`idProfesor` int(11) NOT NULL,
|
||||
`idEstudiante` int(11) NOT NULL,
|
||||
`idMateria` int(11) NOT NULL,
|
||||
`valoracion` float DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `fk_asignatura_profesor_idx` (`idProfesor`),
|
||||
KEY `fk_asignatura_estudiante1_idx` (`idEstudiante`),
|
||||
KEY `fk_asignatura_asignatura1_idx` (`idMateria`),
|
||||
CONSTRAINT `fk_asignatura_asignatura1` FOREIGN KEY (`idMateria`) REFERENCES `materia` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_asignatura_estudiante1` FOREIGN KEY (`idEstudiante`) REFERENCES `estudiante` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_asignatura_profesor` FOREIGN KEY (`idProfesor`) REFERENCES `profesor` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `valoracionmateria`
|
||||
--
|
||||
|
||||
LOCK TABLES `valoracionmateria` WRITE;
|
||||
/*!40000 ALTER TABLE `valoracionmateria` DISABLE KEYS */;
|
||||
INSERT INTO `valoracionmateria` VALUES (1,1,1,1,6),(2,1,1,2,7),(3,2,1,3,6),(4,3,1,4,6),(5,4,1,5,8),(6,5,1,6,4),(7,1,2,1,5),(8,1,2,2,7),(9,2,2,3,8),(10,3,2,4,5),(11,4,2,5,6),(12,5,2,6,4);
|
||||
/*!40000 ALTER TABLE `valoracionmateria` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-04-09 10:05:53
|
||||
File diff suppressed because one or more lines are too long
BIN
BBDDs/03_BBDD_PoblacionEnProvincia/poblacionProvincial.mwb
Normal file
BIN
BBDDs/03_BBDD_PoblacionEnProvincia/poblacionProvincial.mwb
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
137
BBDDs/04_BBDD_Bankonter/bbdd-bankonter.sql
Normal file
137
BBDDs/04_BBDD_Bankonter/bbdd-bankonter.sql
Normal file
File diff suppressed because one or more lines are too long
41154
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/arbol.json
Normal file
41154
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/arbol.json
Normal file
File diff suppressed because it is too large
Load Diff
97
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/ccaa.json
Normal file
97
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/ccaa.json
Normal file
@@ -0,0 +1,97 @@
|
||||
[
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Andalucía",
|
||||
"code": "01"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Aragón",
|
||||
"code": "02"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Asturias, Principado de",
|
||||
"code": "03"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Balears, Illes",
|
||||
"code": "04"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Canarias",
|
||||
"code": "05"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Cantabria",
|
||||
"code": "06"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Castilla y León",
|
||||
"code": "07"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Castilla - La Mancha",
|
||||
"code": "08"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Cataluńa",
|
||||
"code": "09"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Comunitat Valenciana",
|
||||
"code": "10"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Extremadura",
|
||||
"code": "11"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Galicia",
|
||||
"code": "12"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Madrid, Comunidad de",
|
||||
"code": "13"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Murcia, Región de",
|
||||
"code": "14"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Navarra, Comunidad Foral de",
|
||||
"code": "15"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "País Vasco",
|
||||
"code": "16"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Rioja, La",
|
||||
"code": "17"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Ceuta",
|
||||
"code": "18"
|
||||
},
|
||||
{
|
||||
"parent_code": "0",
|
||||
"label": "Melilla",
|
||||
"code": "19"
|
||||
}
|
||||
]
|
||||
40657
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/poblaciones.json
Normal file
40657
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/poblaciones.json
Normal file
File diff suppressed because it is too large
Load Diff
262
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/provincias.json
Normal file
262
BBDDs/05_JSON_CCAA_Provincias_Poblaciones/provincias.json
Normal file
@@ -0,0 +1,262 @@
|
||||
[
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "04",
|
||||
"label": "Almería"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "11",
|
||||
"label": "Cádiz"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "14",
|
||||
"label": "Córdoba"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "18",
|
||||
"label": "Granada"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "21",
|
||||
"label": "Huelva"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "23",
|
||||
"label": "Jaén"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "29",
|
||||
"label": "Málaga"
|
||||
},
|
||||
{
|
||||
"parent_code": "01",
|
||||
"code": "41",
|
||||
"label": "Sevilla"
|
||||
},
|
||||
{
|
||||
"parent_code": "02",
|
||||
"code": "22",
|
||||
"label": "Huesca"
|
||||
},
|
||||
{
|
||||
"parent_code": "02",
|
||||
"code": "44",
|
||||
"label": "Teruel"
|
||||
},
|
||||
{
|
||||
"parent_code": "02",
|
||||
"code": "50",
|
||||
"label": "Zaragoza"
|
||||
},
|
||||
{
|
||||
"parent_code": "03",
|
||||
"code": "33",
|
||||
"label": "Asturias"
|
||||
},
|
||||
{
|
||||
"parent_code": "04",
|
||||
"code": "07",
|
||||
"label": "Balears, Illes"
|
||||
},
|
||||
{
|
||||
"parent_code": "05",
|
||||
"code": "35",
|
||||
"label": "Palmas, Las"
|
||||
},
|
||||
{
|
||||
"parent_code": "05",
|
||||
"code": "38",
|
||||
"label": "Santa Cruz de Tenerife"
|
||||
},
|
||||
{
|
||||
"parent_code": "06",
|
||||
"code": "39",
|
||||
"label": "Cantabria"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "05",
|
||||
"label": "Ávila"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "09",
|
||||
"label": "Burgos"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "24",
|
||||
"label": "León"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "34",
|
||||
"label": "Palencia"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "37",
|
||||
"label": "Salamanca"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "40",
|
||||
"label": "Segovia"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "42",
|
||||
"label": "Soria"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "47",
|
||||
"label": "Valladolid"
|
||||
},
|
||||
{
|
||||
"parent_code": "07",
|
||||
"code": "49",
|
||||
"label": "Zamora"
|
||||
},
|
||||
{
|
||||
"parent_code": "08",
|
||||
"code": "02",
|
||||
"label": "Albacete"
|
||||
},
|
||||
{
|
||||
"parent_code": "08",
|
||||
"code": "13",
|
||||
"label": "Ciudad Real"
|
||||
},
|
||||
{
|
||||
"parent_code": "08",
|
||||
"code": "16",
|
||||
"label": "Cuenca"
|
||||
},
|
||||
{
|
||||
"parent_code": "08",
|
||||
"code": "19",
|
||||
"label": "Guadalajara"
|
||||
},
|
||||
{
|
||||
"parent_code": "08",
|
||||
"code": "45",
|
||||
"label": "Toledo"
|
||||
},
|
||||
{
|
||||
"parent_code": "09",
|
||||
"code": "08",
|
||||
"label": "Barcelona"
|
||||
},
|
||||
{
|
||||
"parent_code": "09",
|
||||
"code": "17",
|
||||
"label": "Girona"
|
||||
},
|
||||
{
|
||||
"parent_code": "09",
|
||||
"code": "25",
|
||||
"label": "Lleida"
|
||||
},
|
||||
{
|
||||
"parent_code": "09",
|
||||
"code": "43",
|
||||
"label": "Tarragona"
|
||||
},
|
||||
{
|
||||
"parent_code": "10",
|
||||
"code": "03",
|
||||
"label": "Alicante/Alacant"
|
||||
},
|
||||
{
|
||||
"parent_code": "10",
|
||||
"code": "12",
|
||||
"label": "Castellón/Castelló"
|
||||
},
|
||||
{
|
||||
"parent_code": "10",
|
||||
"code": "46",
|
||||
"label": "Valencia/València"
|
||||
},
|
||||
{
|
||||
"parent_code": "11",
|
||||
"code": "06",
|
||||
"label": "Badajoz"
|
||||
},
|
||||
{
|
||||
"parent_code": "11",
|
||||
"code": "10",
|
||||
"label": "Cáceres"
|
||||
},
|
||||
{
|
||||
"parent_code": "12",
|
||||
"code": "15",
|
||||
"label": "Coruña, A"
|
||||
},
|
||||
{
|
||||
"parent_code": "12",
|
||||
"code": "27",
|
||||
"label": "Lugo"
|
||||
},
|
||||
{
|
||||
"parent_code": "12",
|
||||
"code": "32",
|
||||
"label": "Ourense"
|
||||
},
|
||||
{
|
||||
"parent_code": "12",
|
||||
"code": "36",
|
||||
"label": "Pontevedra"
|
||||
},
|
||||
{
|
||||
"parent_code": "13",
|
||||
"code": "28",
|
||||
"label": "Madrid"
|
||||
},
|
||||
{
|
||||
"parent_code": "14",
|
||||
"code": "30",
|
||||
"label": "Murcia"
|
||||
},
|
||||
{
|
||||
"parent_code": "15",
|
||||
"code": "31",
|
||||
"label": "Navarra"
|
||||
},
|
||||
{
|
||||
"parent_code": "16",
|
||||
"code": "01",
|
||||
"label": "Araba/Álava"
|
||||
},
|
||||
{
|
||||
"parent_code": "16",
|
||||
"code": "48",
|
||||
"label": "Bizkaia"
|
||||
},
|
||||
{
|
||||
"parent_code": "16",
|
||||
"code": "20",
|
||||
"label": "Gipuzkoa"
|
||||
},
|
||||
{
|
||||
"parent_code": "17",
|
||||
"code": "26",
|
||||
"label": "Rioja, La"
|
||||
},
|
||||
{
|
||||
"parent_code": "18",
|
||||
"code": "51",
|
||||
"label": "Ceuta"
|
||||
},
|
||||
{
|
||||
"parent_code": "19",
|
||||
"code": "52",
|
||||
"label": "Melilla"
|
||||
}
|
||||
]
|
||||
Binary file not shown.
80
BBDDs/05_MunicipiosYProvincias/municipiosYProvincias.sql
Normal file
80
BBDDs/05_MunicipiosYProvincias/municipiosYProvincias.sql
Normal file
File diff suppressed because one or more lines are too long
1071
BBDDs/06_JSON_West_World_La_serie/westworld-serie.json
Normal file
1071
BBDDs/06_JSON_West_World_La_serie/westworld-serie.json
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
BIN
librerias/EclipseLink2.5.2/jlib/eclipselink.jar
Normal file
BIN
librerias/EclipseLink2.5.2/jlib/eclipselink.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar
Normal file
BIN
librerias/EclipseLink2.5.2/jlib/moxy/com.sun.tools.xjc_2.2.0.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
librerias/JDBC_Oracle_Connection_Pool/ucp.jar
Normal file
BIN
librerias/JDBC_Oracle_Connection_Pool/ucp.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-annotations-2.9.0.jar
Normal file
BIN
librerias/Jackson/jackson-annotations-2.9.0.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-core-2.9.5.jar
Normal file
BIN
librerias/Jackson/jackson-core-2.9.5.jar
Normal file
Binary file not shown.
BIN
librerias/Jackson/jackson-databind-2.9.5.jar
Normal file
BIN
librerias/Jackson/jackson-databind-2.9.5.jar
Normal file
Binary file not shown.
BIN
librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar
Normal file
BIN
librerias/mongoDB-Java-driver/mongo-java-driver-3.12.12.jar
Normal file
Binary file not shown.
@@ -114,6 +114,41 @@ public class Utils {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un número entero a través de un objeto Scanner
|
||||
* @return Número entero introducido por el usuario.
|
||||
*/
|
||||
public static double obtenerDoublePorScanner() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
return sc.nextDouble();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Error, introduce un número double: ");
|
||||
sc.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un número entero a través de un objeto Scanner
|
||||
* @return Número entero introducido por el usuario.
|
||||
*/
|
||||
public static double obtenerDoublePorScanner(String mensaje) {
|
||||
System.out.println(mensaje);
|
||||
return obtenerDoublePorScanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un número entero a través de un objeto Scanner
|
||||
* @return Número entero introducido por el usuario.
|
||||
*/
|
||||
public static float obtenerFloatPorScanner(String mensaje) {
|
||||
return (float) obtenerDoublePorScanner(mensaje);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un número entero a través de un JOptionPane
|
||||
* @return Número entero introducido a través de un JOptionPane.
|
||||
@@ -143,6 +178,11 @@ public class Utils {
|
||||
return num;
|
||||
}
|
||||
|
||||
public static double obtenerDoubleConDescripcion(String desc) {
|
||||
System.out.println(desc);
|
||||
return obtenerDoublePorScanner();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Número entero introducido por el usuario
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package tutorialJava.capitulo6_ColeccionesDeDatos.ejercicios.bloque02_Hashmap;
|
||||
|
||||
public class Articulo {
|
||||
|
||||
private String nombre;
|
||||
private int codigoDeBarras;
|
||||
private int numeroDeEstante;
|
||||
private int stock;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Articulo() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nombre
|
||||
* @param codigoDeBarras
|
||||
* @param numeroDeEstante
|
||||
* @param stock
|
||||
*/
|
||||
public Articulo(String nombre, int codigoDeBarras, int numeroDeEstante, int stock) {
|
||||
super();
|
||||
this.nombre = nombre;
|
||||
this.codigoDeBarras = codigoDeBarras;
|
||||
this.numeroDeEstante = numeroDeEstante;
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
public String getNombre() {
|
||||
return nombre;
|
||||
}
|
||||
public void setNombre(String nombre) {
|
||||
this.nombre = nombre;
|
||||
}
|
||||
public int getCodigoDeBarras() {
|
||||
return codigoDeBarras;
|
||||
}
|
||||
public void setCodigoDeBarras(int codigoDeBarras) {
|
||||
this.codigoDeBarras = codigoDeBarras;
|
||||
}
|
||||
public int getNumeroDeEstante() {
|
||||
return numeroDeEstante;
|
||||
}
|
||||
public void setNumeroDeEstante(int numeroDeEstante) {
|
||||
this.numeroDeEstante = numeroDeEstante;
|
||||
}
|
||||
public int getStock() {
|
||||
return stock;
|
||||
}
|
||||
public void setStock(int stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Articulo [nombre=" + nombre + ", codigoDeBarras=" + codigoDeBarras + ", numeroDeEstante="
|
||||
+ numeroDeEstante + ", stock=" + stock + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package tutorialJava.capitulo6_ColeccionesDeDatos.ejercicios.bloque02_Hashmap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Principal {
|
||||
|
||||
|
||||
private static HashMap<Integer, Articulo> hm =
|
||||
new HashMap<Integer, Articulo> ();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int opcion;
|
||||
Articulo art = null;
|
||||
|
||||
do {
|
||||
opcion = menu(); // Muestro menú y recojo selección del usuario
|
||||
|
||||
// Trato la opción elegida
|
||||
switch (opcion) {
|
||||
case 0:
|
||||
System.exit(0);
|
||||
break;
|
||||
|
||||
case 1: // Ver artículos
|
||||
mostrarArticulos();
|
||||
break;
|
||||
|
||||
case 2: // Insertar artículo
|
||||
insertarArticulo();
|
||||
break;
|
||||
|
||||
case 3: // Eliminar artículo
|
||||
System.out.println("Introduzca el codigo de barras deel artículo a eliminar: ");
|
||||
int codigoAEliminar = sc.nextInt();
|
||||
hm.remove(codigoAEliminar);
|
||||
break;
|
||||
|
||||
case 4: // Modificar artículo
|
||||
modificarArticulo();
|
||||
break;
|
||||
}
|
||||
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static int menu() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Elige lo que desea hacer:");
|
||||
System.out.println("0.-Salir");
|
||||
System.out.println("1.-Ver los objeatos del almecen");
|
||||
System.out.println("2.-Insertar nuevo artículo");
|
||||
System.out.println("3.-Eliminar un articulo");
|
||||
System.out.println("4.-Actualizar un articulo");
|
||||
return sc.nextInt();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void mostrarArticulos() {
|
||||
Object claves[] = hm.keySet().toArray();
|
||||
for (int i = 0; i < claves.length; i++) {
|
||||
System.out.println("Codigo de barras: " + claves[i] +
|
||||
"\nDatos del " + hm.get(claves[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void insertarArticulo() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Introduzca codigo de barras: ");
|
||||
int cB = sc.nextInt();
|
||||
System.out.println("Introduzca nombre: ");
|
||||
String nombre = sc.next();
|
||||
System.out.println("Introduzca número de estanteria: ");
|
||||
int estanteria = sc.nextInt();
|
||||
System.out.println("Introduzca stock: ");
|
||||
int cantidad = sc.nextInt();
|
||||
|
||||
hm.put(cB, new Articulo(nombre, cB, estanteria, cantidad));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void modificarArticulo() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
Articulo art = new Articulo();
|
||||
System.out.println("Introzuca codigo de barras: ");
|
||||
art.setCodigoDeBarras(sc.nextInt());
|
||||
System.out.println("Introduzca nombre: ");
|
||||
art.setNombre(sc.next());
|
||||
System.out.println("Introduzca número de estanteria: ");
|
||||
art.setNumeroDeEstante(sc.nextInt());
|
||||
System.out.println("Introduzca stock: ");
|
||||
art.setStock(sc.nextInt());
|
||||
|
||||
hm.replace(art.getCodigoDeBarras(), art);
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class EjemploFicheroPropiedades {
|
||||
public class Ejemplo01_FicheroPropiedades {
|
||||
|
||||
private static Properties propiedades = null;
|
||||
|
||||
public EjemploFicheroPropiedades () {
|
||||
public Ejemplo01_FicheroPropiedades () {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ public class EjemploFicheroPropiedades {
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String args[]) {
|
||||
String usuario = EjemploFicheroPropiedades.getProperty("USUARIO");
|
||||
String password = EjemploFicheroPropiedades.getProperty("PASSWORD");
|
||||
int id = EjemploFicheroPropiedades.getIntProperty("ID_USUARIO");
|
||||
String usuario = Ejemplo01_FicheroPropiedades.getProperty("USUARIO");
|
||||
String password = Ejemplo01_FicheroPropiedades.getProperty("PASSWORD");
|
||||
int id = Ejemplo01_FicheroPropiedades.getIntProperty("ID_USUARIO");
|
||||
|
||||
System.out.println("Usuario leído del fichero de propiedades: " + usuario);
|
||||
System.out.println("Password leído del fichero de propiedades: " + password);
|
||||
@@ -1,6 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos;
|
||||
|
||||
public class EjemploMath {
|
||||
public class Ejemplo01_Math {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// La clase Math tiene una cantidad importante de métodos que podemos utilizar en cálculos muy diversos
|
||||
@@ -1,6 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos;
|
||||
|
||||
public class EjemploString {
|
||||
public class Ejemplo01_String {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "Cadena de texto de tamaño mediano";
|
||||
@@ -1,6 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos;
|
||||
|
||||
public class EjemploWrappersTiposPrimitivos {
|
||||
public class Ejemplo01_WrappersTiposPrimitivos {
|
||||
|
||||
public static void main (String args[]) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class EjemploDateCalendar {
|
||||
public class Ejemplo02_DateCalendar {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -199,15 +199,15 @@ public class EjemploDateCalendar {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ejemploCreacionNormalDate();
|
||||
// ejemploCreacionNormalDate();
|
||||
// ejemploFormateoFecha();
|
||||
// ejemploCalendarBasico();
|
||||
// ejemploCalendarConCamposIndividualizados();
|
||||
// ejemploLecturaCamposIndividualizadosYLocaleEnImpresion();
|
||||
// ejemploSumaRestaFechas();
|
||||
// ejemploComparacionFechas();
|
||||
//ejemploDiasEntreDosFechas();
|
||||
// ejemploZonasHorarias();
|
||||
// ejemploDiasEntreDosFechas();
|
||||
ejemploZonasHorarias();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos;
|
||||
|
||||
public class EjemploRecursividad_Factorial {
|
||||
public class Ejemplo05_Recursividad_Factorial {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Mediante no recursividad: " + factorialNoRecursivo(6));
|
||||
@@ -24,3 +24,16 @@ public class EjemploRecursividad_Factorial {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -131,7 +131,9 @@ public class EjemploExcepcionesBasico {
|
||||
private static void ejemploClassNotFoundException () {
|
||||
try {
|
||||
// Ejemplo de instanciaci<EFBFBD>n de un objeto
|
||||
Persona persona = (Persona) Class.forName("tutorialJava.capitulo7_Recursos.excepciones.Persona").newInstance();
|
||||
Persona persona = (Persona)
|
||||
Class.forName("tutorialJava.capitulo7_Recursos.excepciones.Persona")
|
||||
.newInstance();
|
||||
System.out.println("Objeto instanciado: " + persona);
|
||||
|
||||
// Ejemplo de obtenci<EFBFBD>n de las propiedades de un objeto
|
||||
@@ -197,10 +199,10 @@ public class EjemploExcepcionesBasico {
|
||||
*/
|
||||
public static void main (String args[]) {
|
||||
|
||||
ejemploExceptionGeneral();
|
||||
// ejemploExceptionGeneral();
|
||||
// ejemploNullPointerException();
|
||||
// ejemploArithmeticException();
|
||||
// ejemploClassCastException();
|
||||
ejemploClassCastException();
|
||||
// ejemploIndexOutOfBoundsException();
|
||||
// ejemploNumberFormatException();
|
||||
// ejemploClassNotFoundException();
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
public class EjemploLanzamientoExcepcionPropia {
|
||||
|
||||
@@ -9,7 +9,9 @@ public class EjemploLanzamientoExcepcionPropia {
|
||||
* @throws PersonaNulaException
|
||||
* @throws PiernaNulaException
|
||||
*/
|
||||
private static String personaToString (Persona persona) throws PersonaNulaException, PiernaNulaException {
|
||||
private static String personaToString (Persona persona)
|
||||
throws PersonaNulaException, PiernaNulaException {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
// A partir de una persona, vamos a construir un StringBuffer que recorra sus dos piernas
|
||||
if (persona == null) {
|
||||
@@ -46,8 +48,10 @@ public class EjemploLanzamientoExcepcionPropia {
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
// Persona persona = new Persona(new Pierna(Pierna.DERECHA), new Pierna(Pierna.IZQUIERDA));
|
||||
Persona persona = null;
|
||||
Persona persona = new Persona(
|
||||
new Pierna(Pierna.DERECHA),
|
||||
new Pierna(Pierna.IZQUIERDA));
|
||||
// Persona persona = null;
|
||||
// Persona persona = new Persona(null, new Pierna(Pierna.IZQUIERDA));
|
||||
// Persona persona = new Persona(new Pierna(Pierna.DERECHA), null);
|
||||
System.out.println(personaToString(persona));
|
||||
@@ -56,6 +60,8 @@ public class EjemploLanzamientoExcepcionPropia {
|
||||
e.printStackTrace();
|
||||
} catch (PiernaNulaException e) {
|
||||
System.out.println("Existen valores nulos en el objeto persona: " + e.getMessage());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
public class Persona {
|
||||
protected Pierna piernaDerecha;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
public class PersonaNulaException extends Exception {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
public class Pierna {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.excepciones;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones;
|
||||
|
||||
public class PiernaNulaException extends Exception {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.palabraRepetidaException;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones.palabraRepetidaException;
|
||||
|
||||
public class PalabraRepetidaException extends Exception {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.palabraRepetidaException;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo03_excepciones.palabraRepetidaException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploEntraPersonaListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploEntraPersonaListener;
|
||||
|
||||
public class Madre implements PersonaEntraListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploEntraPersonaListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploEntraPersonaListener;
|
||||
|
||||
public class Padre implements PersonaEntraListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploEntraPersonaListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploEntraPersonaListener;
|
||||
|
||||
public class PersonaEntraEvent {
|
||||
private String nombrePer;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploEntraPersonaListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploEntraPersonaListener;
|
||||
|
||||
public interface PersonaEntraListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploEntraPersonaListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploEntraPersonaListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploNumeroImparListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploNumeroImparListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,8 +30,8 @@ public class IntroduccionNumeros {
|
||||
*/
|
||||
private static void fireNumeroImparListener(int numeroImparIntroducido) {
|
||||
NumeroImparEvent event = new NumeroImparEvent(numeroImparIntroducido);
|
||||
for (int i = listNumeroImparListeners.size() - 1; i >= 0; i--) {
|
||||
listNumeroImparListeners.get(i).numeroImparIntroducido(event);
|
||||
for (NumeroImparListener listener : listNumeroImparListeners) {
|
||||
listener.numeroImparIntroducido(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploNumeroImparListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploNumeroImparListener;
|
||||
|
||||
public class Mesa implements NumeroImparListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploNumeroImparListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploNumeroImparListener;
|
||||
|
||||
public class NumeroImparEvent {
|
||||
private int numeroIntroducido;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploNumeroImparListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploNumeroImparListener;
|
||||
|
||||
public interface NumeroImparListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploNumeroImparListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploNumeroImparListener;
|
||||
|
||||
public class Perro implements NumeroImparListener {
|
||||
|
||||
@@ -8,7 +8,6 @@ public class Perro implements NumeroImparListener {
|
||||
public void numeroImparIntroducido(NumeroImparEvent e) {
|
||||
System.out.println("Soy un perro y me han notificado la introducción de un número "
|
||||
+ "impar: " + e.getNumeroIntroducido());
|
||||
IntroduccionNumeros.removeNumeroImparListener(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploPalabraRepetidaEnFraseListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploPalabraRepetidaEnFraseListener;
|
||||
|
||||
public class CorrectorOrtografico implements PalabraRepetidaListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploPalabraRepetidaEnFraseListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploPalabraRepetidaEnFraseListener;
|
||||
|
||||
public class Informatica implements PalabraRepetidaListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploPalabraRepetidaEnFraseListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploPalabraRepetidaEnFraseListener;
|
||||
|
||||
public class PalabraRepetidaEvent {
|
||||
String palabra;
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploPalabraRepetidaEnFraseListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploPalabraRepetidaEnFraseListener;
|
||||
|
||||
public interface PalabraRepetidaListener {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemploPalabraRepetidaEnFraseListener;
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.ejemploPalabraRepetidaEnFraseListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -0,0 +1,68 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.lluviaListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Aemet {
|
||||
|
||||
private static List<InteresadoLLuviaListener> lluviaListeners =
|
||||
new ArrayList<InteresadoLLuviaListener>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param l
|
||||
*/
|
||||
public static void addInteresadoLluviaListener (
|
||||
InteresadoLLuviaListener listener) {
|
||||
lluviaListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
public static void removeInteresadoLluviaListener (
|
||||
InteresadoLLuviaListener listener) {
|
||||
lluviaListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void fireEstaLloviendo(int litrosPorMetro) {
|
||||
for (InteresadoLLuviaListener listener : lluviaListeners) {
|
||||
InteresadoLluviaEvent event = new InteresadoLluviaEvent();
|
||||
event.setLitrosPorMetro(litrosPorMetro);
|
||||
listener.estaLloviendo(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String respuestaLluvia;
|
||||
|
||||
new Telediario();
|
||||
new ProgramaRadio();
|
||||
|
||||
|
||||
System.out.println("Está lloviendo?");
|
||||
respuestaLluvia = sc.nextLine();
|
||||
|
||||
if (respuestaLluvia.toLowerCase().startsWith("s")) {
|
||||
System.out.println("Está lloviendo");
|
||||
|
||||
System.out.println("¿Cuánto está lloviendo?");
|
||||
int litrosPorMetro = Integer.parseInt(sc.nextLine());
|
||||
|
||||
fireEstaLloviendo(litrosPorMetro);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.lluviaListener;
|
||||
|
||||
public interface InteresadoLLuviaListener {
|
||||
|
||||
public void estaLloviendo(InteresadoLluviaEvent event);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.lluviaListener;
|
||||
|
||||
public class InteresadoLluviaEvent {
|
||||
|
||||
private int litrosPorMetro;
|
||||
|
||||
public InteresadoLluviaEvent() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getLitrosPorMetro() {
|
||||
return litrosPorMetro;
|
||||
}
|
||||
|
||||
public void setLitrosPorMetro(int litrosPorMetro) {
|
||||
this.litrosPorMetro = litrosPorMetro;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.lluviaListener;
|
||||
|
||||
public class ProgramaRadio implements InteresadoLLuviaListener {
|
||||
|
||||
public ProgramaRadio () {
|
||||
Aemet.addInteresadoLluviaListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void estaLloviendo(InteresadoLluviaEvent event) {
|
||||
System.out.println("Soy un programa de radio y me notifican que llueve");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejemplo04_listeners.lluviaListener;
|
||||
|
||||
public class Telediario implements InteresadoLLuviaListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Telediario() {
|
||||
Aemet.addInteresadoLluviaListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void estaLloviendo(InteresadoLluviaEvent event) {
|
||||
System.out.println("Soy un telediario y me dicen que llueve "
|
||||
+ event.getLitrosPorMetro() + " litros por metro");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque01_WrappersDeTiposPrimitivos;
|
||||
|
||||
public class Ejercicio01_TablaConCaracteristicasDeTiposPrimitivos {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// Características de un Integer
|
||||
System.out.println("Valor máximo para un Integer: " + Integer.MAX_VALUE);
|
||||
System.out.println("Valor mínimo para un Integer: " + Integer.MIN_VALUE);
|
||||
System.out.println("Tamaño en bits complemento a 2 para Integer: " + Integer.SIZE);
|
||||
|
||||
// Características de un Long
|
||||
System.out.println("\nValor máximo para un Long: " + Long.MAX_VALUE);
|
||||
System.out.println("Valor mínimo para un Long: " + Long.MIN_VALUE);
|
||||
System.out.println("Tamaño en bits complemento a 2 para Long: " + Long.SIZE);
|
||||
|
||||
// Características de un Short
|
||||
System.out.println("\nValor máximo para un Short: " + Short.MAX_VALUE);
|
||||
System.out.println("Valor mínimo para un Short: " + Short.MIN_VALUE);
|
||||
System.out.println("Tamaño en bits complemento a 2 para Short: " + Short.SIZE);
|
||||
|
||||
// Características de un Float
|
||||
System.out.println("\nValor máximo para un Float: " + Float.MAX_VALUE);
|
||||
System.out.println("Valor mínimo para un Float: " + Float.MIN_VALUE);
|
||||
System.out.println("Tamaño en bits complemento a 2 para Float: " + Float.SIZE);
|
||||
|
||||
// Características de un Double
|
||||
System.out.println("\nValor máximo para un Double: " + Double.MAX_VALUE);
|
||||
System.out.println("Valor mínimo para un Double: " + Double.MIN_VALUE);
|
||||
System.out.println("Tamaño en bits complemento a 2 para Double: " + Double.SIZE);
|
||||
|
||||
// Wrapper para el tipo de datos "Character"
|
||||
System.out.println("Tamaño en bits complemento a 2 para Character: " + Character.SIZE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque01_WrappersDeTiposPrimitivos;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Ejercicio02_PedirPasswordConRequisitos {
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean mayuscula = false;
|
||||
boolean minuscula = false;
|
||||
boolean digito = false;
|
||||
boolean noAlfanumerico = false;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
do {
|
||||
mayuscula = false;
|
||||
minuscula = false;
|
||||
digito = false;
|
||||
noAlfanumerico = false;
|
||||
|
||||
System.out.println("Dame una contraseña con mayúsculas, minúsculas, dígitos y algún carácter no alfanumérico: ");
|
||||
String password = sc.next();
|
||||
|
||||
for (int i = 0; i < password.length(); i++) {
|
||||
if (Character.isUpperCase(password.charAt(i))) {
|
||||
mayuscula = true;
|
||||
}
|
||||
if (Character.isLowerCase(password.charAt(i))) {
|
||||
minuscula = true;
|
||||
}
|
||||
if (Character.isDigit(password.charAt(i))) {
|
||||
digito = true;
|
||||
}
|
||||
if (!Character.isLetterOrDigit(password.charAt(i))) {
|
||||
noAlfanumerico = true;
|
||||
}
|
||||
}
|
||||
} while (!(mayuscula && minuscula && digito && noAlfanumerico));
|
||||
|
||||
// Contraseña establecida
|
||||
System.out.println("Contraseña establecida :-)");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque01_WrappersDeTiposPrimitivos;
|
||||
|
||||
public class Ejercicio03_100PrimerosNumerosEnHexadecimal {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
for (int i = 0; i < 101; i++) {
|
||||
System.out.println("Decimal: " + i + " - Hexadecimal: 0x" + Integer.toHexString(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Ejemplo de comentario en fichero de propiedades
|
||||
|
||||
# Propiedades
|
||||
USUARIO=RafaelMunoz77
|
||||
PASSWORD=1<EFBFBD>DAWlosmejores
|
||||
ID_USUARIO=1523
|
||||
TODO_CORRECTO=true
|
||||
@@ -0,0 +1,95 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque01_WrappersDeTiposPrimitivos;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
|
||||
public class Ejercicio04_LecturaFicheroPropiedades {
|
||||
private static Properties propiedades = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static Properties getPropiedades() {
|
||||
if (propiedades == null) {
|
||||
propiedades = new Properties();
|
||||
|
||||
try {
|
||||
// Otra forma de leer el fichero de propiedades
|
||||
File file = new File("./src/tutorialJava/capitulo7_Recursos/ejercicios/bloque01_WrappersDeTiposPrimitivos/Ejercicio04.properties");
|
||||
System.out.println("Fichero encontrado: " + file.exists());
|
||||
propiedades.load(new FileReader(file));
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return propiedades;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nombrePropiedad
|
||||
* @return
|
||||
*/
|
||||
public static String getProperty(String nombrePropiedad) {
|
||||
return getPropiedades().getProperty(nombrePropiedad);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nombrePropiedad
|
||||
* @return
|
||||
*/
|
||||
public static int getIntProperty (String nombrePropiedad) {
|
||||
return Integer.parseInt(getPropiedades().getProperty(nombrePropiedad));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nombrePropiedad
|
||||
* @return
|
||||
*/
|
||||
public static Float getFloatProperty (String nombrePropiedad) {
|
||||
return Float.parseFloat(getPropiedades().getProperty(nombrePropiedad));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nombrePropiedad
|
||||
* @return
|
||||
*/
|
||||
public static Boolean getBooleanProperty (String nombrePropiedad) {
|
||||
return Boolean.parseBoolean(getPropiedades().getProperty(nombrePropiedad));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main (String args[]) {
|
||||
String usuario = Ejercicio04_LecturaFicheroPropiedades.getProperty("USUARIO");
|
||||
String password = Ejercicio04_LecturaFicheroPropiedades.getProperty("PASSWORD");
|
||||
int id = Ejercicio04_LecturaFicheroPropiedades.getIntProperty("ID_USUARIO");
|
||||
boolean todoCorrecto = Ejercicio04_LecturaFicheroPropiedades.getBooleanProperty("TODO_CORRECTO");
|
||||
|
||||
System.out.println("Usuario leído del fichero de propiedades: " + usuario);
|
||||
System.out.println("Password leído del fichero de propiedades: " + password);
|
||||
System.out.println("Id de usuario leído del fichero de propiedades: " + id);
|
||||
System.out.println("Todo correcto: " + todoCorrecto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque02_MathDateCalendar;
|
||||
|
||||
public class Ejercicio01_PuntoDeCorteDeDosGraficas {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
double x = 0, y1 = 0, y2 = 0;
|
||||
|
||||
for (x = 0; x < 1; x+=0.0001) {
|
||||
y1 = Math.sqrt(x);
|
||||
y2 = - Math.log(x);
|
||||
|
||||
if (Math.abs(y1 - y2) < 0.001) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Cruce encontrado en x: " + x + " y: " + ((y1 + y2) / 2f));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque02_MathDateCalendar;
|
||||
|
||||
public class Ejercicio02_PI_SeriesInfinitas_GregoryLeibniz {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
double PI = 0;
|
||||
int signo = 1;
|
||||
int denominador = 1;
|
||||
|
||||
while (Math.abs(Math.PI - PI) > 0.00001) {
|
||||
PI += signo * (4f / denominador);
|
||||
signo = -signo;
|
||||
denominador += 2;
|
||||
}
|
||||
|
||||
System.out.println("PI: " + PI);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque02_MathDateCalendar;
|
||||
|
||||
public class Ejercicio03_Hipotenusa {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println("Hipotenusa de un triángulo rectángulo con catetos 4 y 5cm: " +
|
||||
Math.hypot(4, 5));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque02_MathDateCalendar;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class Ejercicio04_DateCalendar {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Date date = pideFechaConFormat("dd/MM/yyyy");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(date.getTime());
|
||||
|
||||
System.out.println("Año del date: " + new SimpleDateFormat("yyyy").format(date));
|
||||
System.out.println("Mes del date: " + new SimpleDateFormat("MMM").format(date));
|
||||
System.out.println("Día del date: " + new SimpleDateFormat("dd").format(date));
|
||||
System.out.println("Hora del date: " + new SimpleDateFormat("HH").format(date));
|
||||
System.out.println("Minuto del date: " + new SimpleDateFormat("mm").format(date));
|
||||
System.out.println("Segundo del date: " + new SimpleDateFormat("ss").format(date));
|
||||
|
||||
System.out.println("\nAño del calendar: " + calendar.get(Calendar.YEAR));
|
||||
System.out.println("Mes del calendar: " + calendar.get(Calendar.MONTH));
|
||||
System.out.println("Día del calendar: " + calendar.get(Calendar.DAY_OF_MONTH));
|
||||
System.out.println("Hora del calendar: " + calendar.get(Calendar.HOUR_OF_DAY));
|
||||
System.out.println("Minuto del calendar: " + calendar.get(Calendar.MINUTE));
|
||||
System.out.println("Segundo del calendar: " + calendar.get(Calendar.SECOND));
|
||||
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 3); System.out.println("\nCalendar más 3 días: " + calendar.getTime());
|
||||
calendar.add(Calendar.DAY_OF_YEAR, -14); System.out.println("Calendar menos 2 semanas: " + calendar.getTime());
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 300); System.out.println("Calendar más 300 días: " + calendar.getTime());
|
||||
calendar.add(Calendar.YEAR, 4); System.out.println("Calendar más 4 años: " + calendar.getTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param formato
|
||||
* @return
|
||||
*/
|
||||
private static Date pideFechaConFormat (String formato) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(formato);
|
||||
|
||||
do {
|
||||
try {
|
||||
return sdf.parse(JOptionPane.showInputDialog("Introduzca una fecha con formato dd/MM/yyyy: "));
|
||||
} catch (ParseException e) {
|
||||
System.out.println("Fecha con formato incorrecto. Vuelva a intentarlo");
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque02_MathDateCalendar;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Ejercicio05_DiferenciaHorariaEntreCiudades {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Calendar ahoraEnRoma = Calendar.getInstance(TimeZone.getTimeZone("Europe/Rome"));
|
||||
Calendar ahoraEnWashington = Calendar.getInstance(TimeZone.getTimeZone("EST"));
|
||||
|
||||
int horaEnRoma = ahoraEnRoma.get(Calendar.HOUR_OF_DAY);
|
||||
int horaEnWashington = ahoraEnWashington.get(Calendar.HOUR_OF_DAY);
|
||||
|
||||
System.out.println("Diferencia horaria entre Roma y Wasington: " + Math.abs(horaEnRoma - horaEnWashington));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorFraseConPalabraBombilla;
|
||||
|
||||
public class MinimoNumeroDePalabrasNoAlcanzadoException extends Exception {
|
||||
|
||||
private int minimoNumeroPalabras;
|
||||
|
||||
public MinimoNumeroDePalabrasNoAlcanzadoException(int minimoNumeroPalabras) {
|
||||
this.minimoNumeroPalabras = minimoNumeroPalabras;
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MinimoNumeroDePalabrasNoAlcanzadoException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MinimoNumeroDePalabrasNoAlcanzadoException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MinimoNumeroDePalabrasNoAlcanzadoException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public MinimoNumeroDePalabrasNoAlcanzadoException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public int getMinimoNumeroPalabras() {
|
||||
return minimoNumeroPalabras;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorFraseConPalabraBombilla;
|
||||
|
||||
public class PalabraBombillaNoEncontradaException extends Exception {
|
||||
|
||||
public PalabraBombillaNoEncontradaException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraBombillaNoEncontradaException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraBombillaNoEncontradaException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraBombillaNoEncontradaException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraBombillaNoEncontradaException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorFraseConPalabraBombilla;
|
||||
|
||||
public class PalabraOfensivaException extends Exception {
|
||||
|
||||
public PalabraOfensivaException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraOfensivaException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraOfensivaException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraOfensivaException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public PalabraOfensivaException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorFraseConPalabraBombilla;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class Principal {
|
||||
|
||||
|
||||
private static String getFraseConPalabraBombilla () throws SoloEspaciosEnBlancoException,
|
||||
MinimoNumeroDePalabrasNoAlcanzadoException,
|
||||
PalabraBombillaNoEncontradaException,
|
||||
PalabraOfensivaException {
|
||||
|
||||
String frase = JOptionPane.showInputDialog("Introduzca una frase con la palabra \"bombilla\"");
|
||||
|
||||
// No frase formada por espacios en blanco
|
||||
if (frase.trim().equals("")) {
|
||||
throw new SoloEspaciosEnBlancoException("No hay palabras en la frase introducida");
|
||||
}
|
||||
// Mínimo número de palabras en 3.
|
||||
String palabras[] = frase.split("[ ]{1,}");
|
||||
if (palabras.length < 3) {
|
||||
throw new MinimoNumeroDePalabrasNoAlcanzadoException(3);
|
||||
}
|
||||
|
||||
// No aparece la palabra bombilla
|
||||
if (frase.toUpperCase().indexOf("BOMBILLA") == -1) {
|
||||
throw new PalabraBombillaNoEncontradaException();
|
||||
}
|
||||
|
||||
// Comprobar palabras ofensivas
|
||||
String palabrasOfensivas[] = new String[] {"tonto", "tonta", "idiota"};
|
||||
for (String palabraOfensiva : palabrasOfensivas) {
|
||||
if (frase.toLowerCase().indexOf(palabraOfensiva) != -1) {
|
||||
throw new PalabraOfensivaException("Palabra " +
|
||||
palabraOfensiva + " encontrada");
|
||||
}
|
||||
}
|
||||
|
||||
return frase;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
System.out.println(getFraseConPalabraBombilla());
|
||||
} catch (SoloEspaciosEnBlancoException e) {
|
||||
System.out.println(e.getMessage());
|
||||
} catch (MinimoNumeroDePalabrasNoAlcanzadoException e) {
|
||||
System.out.println("Tu frase debería ser más larga, al menos: " +
|
||||
e.getMinimoNumeroPalabras() + " palabras");
|
||||
} catch (PalabraBombillaNoEncontradaException e) {
|
||||
e.printStackTrace();
|
||||
} catch (PalabraOfensivaException e) {
|
||||
System.out.println(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorFraseConPalabraBombilla;
|
||||
|
||||
public class SoloEspaciosEnBlancoException extends Exception {
|
||||
|
||||
public SoloEspaciosEnBlancoException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public SoloEspaciosEnBlancoException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public SoloEspaciosEnBlancoException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public SoloEspaciosEnBlancoException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public SoloEspaciosEnBlancoException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorNumeroPar;
|
||||
|
||||
public class NumeroImparException extends Exception {
|
||||
|
||||
public NumeroImparException() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NumeroImparException(String arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NumeroImparException(Throwable arg0) {
|
||||
super(arg0);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NumeroImparException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NumeroImparException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
|
||||
super(arg0, arg1, arg2, arg3);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque03_Excepciones.ExcepcionPorNumeroPar;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Principal {
|
||||
|
||||
private static int getNumeroPar () throws NumeroImparException {
|
||||
System.out.println("Introduzca número par: ");
|
||||
Scanner sc = new Scanner (System.in);
|
||||
int numero = sc.nextInt();
|
||||
|
||||
if (numero % 2 == 0) {
|
||||
return numero;
|
||||
}
|
||||
else {
|
||||
throw new NumeroImparException("El número: " + numero + " no es par");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
getNumeroPar();
|
||||
} catch (NumeroImparException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque04_Listener;
|
||||
|
||||
public class Mesa implements OperacionMatematicaListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Mesa() {
|
||||
Principal.addOperacionMatematicaListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sumaMayorA1000(SumaMayorA1000Event e) {
|
||||
System.out.println("Soy una mesa y una suma ha dado "
|
||||
+ "un valor > 1000, que es: " + e.getSuma());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque04_Listener;
|
||||
|
||||
public interface OperacionMatematicaListener {
|
||||
|
||||
public void sumaMayorA1000(SumaMayorA1000Event e);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque04_Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Principal {
|
||||
|
||||
private static List<OperacionMatematicaListener> listeners = new ArrayList<OperacionMatematicaListener>();
|
||||
|
||||
public static void addOperacionMatematicaListener (OperacionMatematicaListener l) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public static void removeOperacionMatematicaListener (OperacionMatematicaListener l) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
|
||||
|
||||
private static void fireSumaMayorA1000(int suma) {
|
||||
SumaMayorA1000Event e = new SumaMayorA1000Event(suma);
|
||||
for (OperacionMatematicaListener l : listeners) {
|
||||
l.sumaMayorA1000(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int choice;
|
||||
|
||||
Mesa m1 = new Mesa();
|
||||
|
||||
|
||||
do {
|
||||
|
||||
choice = menu();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
// Suma
|
||||
System.out.print("Ingrese el primer número: ");
|
||||
int sum1 = scanner.nextInt();
|
||||
System.out.print("Ingrese el segundo número: ");
|
||||
int sum2 = scanner.nextInt();
|
||||
int suma = sum1 + sum2;
|
||||
if (suma > 1000) {
|
||||
fireSumaMayorA1000(suma);
|
||||
}
|
||||
System.out.println("Resultado de la suma: " + suma);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// Resta
|
||||
System.out.print("Ingrese el primer número: ");
|
||||
int sub1 = scanner.nextInt();
|
||||
System.out.print("Ingrese el segundo número: ");
|
||||
int sub2 = scanner.nextInt();
|
||||
System.out.println("Resultado de la resta: " + (sub1 - sub2));
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// Multiplicación
|
||||
System.out.print("Ingrese el primer número: ");
|
||||
int mul1 = scanner.nextInt();
|
||||
System.out.print("Ingrese el segundo número: ");
|
||||
int mul2 = scanner.nextInt();
|
||||
System.out.println("Resultado de la multiplicación: " + (mul1 * mul2));
|
||||
break;
|
||||
|
||||
case 4:
|
||||
// División
|
||||
System.out.print("Ingrese el dividendo: ");
|
||||
int dividend = scanner.nextInt();
|
||||
System.out.print("Ingrese el divisor: ");
|
||||
int divisor = scanner.nextInt();
|
||||
|
||||
if (divisor != 0) {
|
||||
System.out.println("Resultado de la división: " + (dividend / divisor));
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
// Raíz cuadrada
|
||||
System.out.print("Ingrese el número: ");
|
||||
int number = scanner.nextInt();
|
||||
|
||||
if (number >= 0) {
|
||||
System.out.println("Resultado de la raíz cuadrada: " + Math.sqrt(number));
|
||||
}
|
||||
break;
|
||||
|
||||
case 0:
|
||||
System.out.println("Saliendo del programa. ¡Adiós!");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Opción no válida. Intente de nuevo.");
|
||||
break;
|
||||
}
|
||||
|
||||
} while (choice != 0);
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static int menu() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
System.out.println("\nMenú de Operaciones Matemáticas:");
|
||||
System.out.println("0. Salir");
|
||||
System.out.println("1. Suma");
|
||||
System.out.println("2. Resta");
|
||||
System.out.println("3. Multiplicación");
|
||||
System.out.println("4. División");
|
||||
System.out.println("5. Raíz Cuadrada");
|
||||
System.out.print("Seleccione una opción: ");
|
||||
|
||||
return scanner.nextInt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque04_Listener;
|
||||
|
||||
public class SumaMayorA1000Event {
|
||||
|
||||
int suma;
|
||||
|
||||
public SumaMayorA1000Event(int suma) {
|
||||
super();
|
||||
this.suma = suma;
|
||||
}
|
||||
|
||||
public int getSuma() {
|
||||
return suma;
|
||||
}
|
||||
|
||||
public void setSuma(int suma) {
|
||||
this.suma = suma;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SumaMayorA1000Event [suma=" + suma + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque05_recursividad;
|
||||
|
||||
public class Ejercicio01_FibonacciRecursivo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int n = 7;
|
||||
System.out.println("El término " + n + " de la secuencia de Fibonacci es: " + fibonacci(n));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param n
|
||||
* @return
|
||||
*/
|
||||
public static int fibonacci(int n) {
|
||||
if (n <= 1) {
|
||||
return n; // Caso base: fibonacci(0) = 0 y fibonacci(1) = 1
|
||||
}
|
||||
return fibonacci(n - 1) + fibonacci(n - 2); // Llamadas recursivas
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque05_recursividad;
|
||||
|
||||
public class Ejercicio02_PotenciaRecursiva {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param base
|
||||
* @param exponent
|
||||
* @return
|
||||
*/
|
||||
public static int potencia(int base, int exponente) {
|
||||
// Cualquier número elevado a 0 es 1
|
||||
if (exponente == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return base * potencia(base, exponente - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Pruebas
|
||||
int base = 2;
|
||||
int exponent = 7;
|
||||
|
||||
System.out.println(base + " elevado a la " + exponent + " es: " + potencia(base, exponent));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package tutorialJava.capitulo7_Recursos.ejercicios.bloque05_recursividad;
|
||||
|
||||
public class Ejercicio03_ConteoRegresivo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
int numero = 10;
|
||||
System.out.println("Conteo regresivo desde " + numero + ":");
|
||||
conteoRegresivo(numero);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param n
|
||||
*/
|
||||
public static void conteoRegresivo(int n) {
|
||||
if (n == 0) {
|
||||
return; // Cuando n llega a 0, termina la recursividad
|
||||
}
|
||||
System.out.println(n);
|
||||
conteoRegresivo(n - 1); // Llamada recursiva con n-1
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package tutorialJava.capitulo8_Acceso_A_Datos.mongoDB;
|
||||
|
||||
import org.bson.BsonDocument;
|
||||
import org.bson.BsonInt64;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
public class Ej01_ConexionBasica_Ping {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/");
|
||||
MongoClient mongoClient = MongoClients.create(connectionString);
|
||||
|
||||
MongoDatabase database = mongoClient.getDatabase("ComunidadesProvinciasPoblaciones");
|
||||
Bson command = new BsonDocument("ping", new BsonInt64(1));
|
||||
database.runCommand(command);
|
||||
System.out.println("Pinged your deployment. You successfully connected to MongoDB!");
|
||||
} catch (MongoException me) {
|
||||
System.err.println(me);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package tutorialJava.capitulo8_Acceso_A_Datos.mongoDB;
|
||||
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientURI;
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoCursor;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.Filters;
|
||||
import com.mongodb.client.model.Updates;
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
|
||||
|
||||
public class Ej02_ObtencionElementos {
|
||||
|
||||
|
||||
// Obtener todos los documentos de una colección.
|
||||
private static void getAllDocuments(MongoCollection<Document> col) {
|
||||
System.out.println("Obteniendo todos los elementos de la colección");
|
||||
|
||||
// Performing a read operation on the collection.
|
||||
FindIterable<Document> fi = col.find();
|
||||
MongoCursor<Document> cursor = fi.iterator();
|
||||
try {
|
||||
while(cursor.hasNext()) {
|
||||
System.out.println(cursor.next().toJson());
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Filtrar documentos dentro de una colección.
|
||||
private static void getSelectiveDocument(MongoCollection<Document> col) {
|
||||
System.out.println("Filtrando elementos de una colección");
|
||||
|
||||
// Performing a read operation on the collection.
|
||||
FindIterable<Document> fi = col.find(Filters.eq("label", "Andalucía"));
|
||||
MongoCursor<Document> cursor = fi.iterator();
|
||||
try {
|
||||
while(cursor.hasNext()) {
|
||||
System.out.println(cursor.next().toJson());
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Obtener documentos que no cumplan un criterio.
|
||||
private static void getDocumentsWithNotInClause(MongoCollection<Document> col) {
|
||||
System.out.println("Filtrando documentos con una claúsula 'not in'");
|
||||
|
||||
// Performing a read operation on the collection.
|
||||
FindIterable<Document> fi = col.find(Filters.ne("label", "Andalucía"));
|
||||
MongoCursor<Document> cursor = fi.iterator();
|
||||
try {
|
||||
while(cursor.hasNext()) {
|
||||
System.out.println(cursor.next().toJson());
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ejemplo de modificación de una entidad
|
||||
* @param col
|
||||
*/
|
||||
private static void updateDocument (MongoCollection<Document> col) {
|
||||
try {
|
||||
Document query = new Document().append("code", "01");
|
||||
Bson update = Updates.combine(Updates.set("label", "Andalucía 02"));
|
||||
UpdateResult result = col.updateOne(query, update);
|
||||
|
||||
System.out.println("Modificados: " + result.getModifiedCount());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param col
|
||||
*/
|
||||
private static void insertDocument (MongoCollection<Document> col) {
|
||||
try {
|
||||
Document doc = new Document().append("parent_code", "0")
|
||||
.append("code", "20")
|
||||
.append("label", "Gibraltar");
|
||||
col.insertOne(doc);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param col
|
||||
*/
|
||||
private static void deleteDocument (MongoCollection<Document> col) {
|
||||
try {
|
||||
Bson query = Filters.eq("code", "20");
|
||||
DeleteResult result = col.deleteOne(query);
|
||||
|
||||
System.out.println("Eliminados: " + result.getDeletedCount());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// Mongodb inicializando parámetros.
|
||||
int port_no = 27017;
|
||||
String host_name = "localhost", db_name = "ComunidadesProvinciasPoblaciones",
|
||||
db_coll_name = "ccaa";
|
||||
|
||||
// Mongodb creando la cadena de conexión.
|
||||
String client_url = "mongodb://" + host_name + ":" + port_no + "/" + db_name;
|
||||
MongoClientURI uri = new MongoClientURI(client_url);
|
||||
|
||||
// Conectando y obteniendo un cliente.
|
||||
MongoClient mongo_client = new MongoClient(uri);
|
||||
|
||||
// Obteniendo un enlace a la base de datos.
|
||||
MongoDatabase db = mongo_client.getDatabase(db_name);
|
||||
|
||||
// Obteniendo la colección de la base de datos
|
||||
MongoCollection<Document> coll = db.getCollection(db_coll_name);
|
||||
|
||||
// Obteniendo todos los documentos de la colección.
|
||||
// getAllDocuments(coll); System.out.println("\n");
|
||||
|
||||
// Filtrando documentos mediante una claúsula "eq".
|
||||
// getSelectiveDocument(coll); System.out.println("\n");
|
||||
|
||||
// Filtrando documentos con una claúsula "neq".
|
||||
// getDocumentsWithNotInClause(coll); System.out.println();
|
||||
|
||||
// Modificación de una entidad
|
||||
// updateDocument(coll);
|
||||
|
||||
// Inserción de una entidad
|
||||
// insertDocument(coll);
|
||||
|
||||
// Eliminación de una entidad
|
||||
// deleteDocument(coll);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package tutorialJava.capitulo8_Acceso_A_Datos.mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
||||
|
||||
public class ConnectionManagerV1 {
|
||||
|
||||
private static Connection conexion = null;
|
||||
|
||||
|
||||
public static Connection getConexion () throws SQLException {
|
||||
// Si es la primera vez que accedemos a la conexi<78>n, debemos instanciarla
|
||||
if (conexion == null) {
|
||||
conectar();
|
||||
}
|
||||
// Compruebo si la conexi<78>n sigue estando activa
|
||||
while (!conexion.isValid(5)) {
|
||||
conectar();
|
||||
}
|
||||
|
||||
return conexion;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void conectar () throws SQLException {
|
||||
String driver = JDBCPropiedades.getProperty("JDBC_DRIVER_CLASS");
|
||||
String user = JDBCPropiedades.getProperty("JDBC_USER");
|
||||
String password = JDBCPropiedades.getProperty("JDBC_PASSWORD");
|
||||
String host = JDBCPropiedades.getProperty("JDBC_HOST");
|
||||
String schema = JDBCPropiedades.getProperty("JDBC_SCHEMA_NAME");
|
||||
String properties = JDBCPropiedades.getProperty("JDBC_PROPERTIES");
|
||||
|
||||
|
||||
try {
|
||||
Class.forName(driver);
|
||||
|
||||
conexion = (Connection) DriverManager.getConnection ("jdbc:mysql://" + host + "/" + schema + properties, user, password);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
System.out.println("Imposible acceder al driver Mysql");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package tutorialJava.capitulo8_Acceso_A_Datos.mysql;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class Ejemplo01_ConexionBasica {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void pruebaConsultaBasica () {
|
||||
try {
|
||||
// A través de la siguiente línea comprobamos si tenemos acceso al driver MySQL, si no fuera así
|
||||
// no podemos trabajar con esa BBDD.
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
||||
// Necesitamos obtener un acceso a la BBDD, eso se materializa en un objeto de tipo Connection, al cual
|
||||
// le tenemos que pasar los parámetros de conexión.
|
||||
Connection conexion =
|
||||
(Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://localhost:3310/tutorialjavacoches?serverTimezone=UTC",
|
||||
"root", "1234");
|
||||
|
||||
|
||||
// Para poder ejecutar una consulta necesitamos utilizar un objeto de tipo Statement
|
||||
Statement s = (Statement) conexion.createStatement();
|
||||
|
||||
// La ejecución de la consulta se realiza a través del objeto Statement y se recibe en forma de objeto
|
||||
// de tipo ResultSet, que puede ser navegado para descubrir todos los registros obtenidos por la consulta
|
||||
ResultSet rs = s.executeQuery ("select * from coche");
|
||||
|
||||
// Navegación del objeto ResultSet
|
||||
while (rs.next()) {
|
||||
System.out.println (rs.getInt("id") + " " + rs.getString (2)+
|
||||
" " + rs.getString(3) + " " + rs.getString(4) +
|
||||
" " + rs.getString(5));
|
||||
}
|
||||
// Cierre de los elementos
|
||||
rs.close();
|
||||
s.close();
|
||||
conexion.close();
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
System.out.println("Imposible acceder al driver Mysql");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
System.out.println("Error en la ejecución SQL: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static void pruebaConsultaPorFicheroDePropiedades () {
|
||||
|
||||
String driver = JDBCPropiedades.getProperty("JDBC_DRIVER_CLASS");
|
||||
String user = JDBCPropiedades.getProperty("JDBC_USER");
|
||||
String password = JDBCPropiedades.getProperty("JDBC_PASSWORD");
|
||||
String host = JDBCPropiedades.getProperty("JDBC_HOST");
|
||||
String schema = JDBCPropiedades.getProperty("JDBC_SCHEMA_NAME");
|
||||
String properties = JDBCPropiedades.getProperty("JDBC_PROPERTIES");
|
||||
|
||||
|
||||
try {
|
||||
// A través de la siguiente línea comprobamos si tenemos acceso al driver MySQL, si no fuera así
|
||||
// no podemos trabajar con esa BBDD.
|
||||
Class.forName(driver);
|
||||
|
||||
// Necesitamos obtener un acceso a la BBDD, eso se materializa en un objeto de tipo Connection, al cual
|
||||
// le tenemos que pasar los parámetros de conexión.
|
||||
Connection conexion = (Connection) DriverManager.getConnection (
|
||||
"jdbc:mysql://" + host + "/" + schema + properties,
|
||||
user, password);
|
||||
|
||||
// Para poder ejecutar una consulta necesitamos utilizar un objeto de tipo Statement
|
||||
Statement s = (Statement) conexion.createStatement();
|
||||
|
||||
// La ejecución de la consulta se realiza a través del objeto Statement y se recibe en forma de objeto
|
||||
// de tipo ResultSet, que puede ser navegado para descubrir todos los registros obtenidos por la consulta
|
||||
ResultSet rs = s.executeQuery ("select * from coche");
|
||||
|
||||
// Navegaci<63>n del objeto ResultSet
|
||||
while (rs.next()) {
|
||||
System.out.println (rs.getInt (1) + " " + rs.getString (2)+ " " + rs.getString(3));
|
||||
}
|
||||
|
||||
// Cierre de los elementos
|
||||
rs.close();
|
||||
s.close();
|
||||
conexion.close();
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
System.out.println("Imposible acceder al driver Mysql");
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
System.out.println("Error en la ejecución SQL: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
pruebaConsultaBasica();
|
||||
// pruebaConsultaPorFicheroDePropiedades();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user