| @ -0,0 +1,11 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <classpath> | |||||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | |||||
| <attributes> | |||||
| <attribute name="module" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="src" path="src"/> | |||||
| <classpathentry kind="lib" path="C:/Users/crist/Downloads/mysql-connector-java-8.0.30.jar"/> | |||||
| <classpathentry kind="output" path="bin"/> | |||||
| </classpath> | |||||
| @ -0,0 +1,17 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <projectDescription> | |||||
| <name>Actividad9</name> | |||||
| <comment></comment> | |||||
| <projects> | |||||
| </projects> | |||||
| <buildSpec> | |||||
| <buildCommand> | |||||
| <name>org.eclipse.jdt.core.javabuilder</name> | |||||
| <arguments> | |||||
| </arguments> | |||||
| </buildCommand> | |||||
| </buildSpec> | |||||
| <natures> | |||||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||||
| </natures> | |||||
| </projectDescription> | |||||
| @ -0,0 +1,2 @@ | |||||
| eclipse.preferences.version=1 | |||||
| encoding/<project>=UTF-8 | |||||
| @ -0,0 +1,14 @@ | |||||
| eclipse.preferences.version=1 | |||||
| org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | |||||
| org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||||
| org.eclipse.jdt.core.compiler.compliance=17 | |||||
| org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||||
| org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||||
| org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |||||
| org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | |||||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |||||
| org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | |||||
| org.eclipse.jdt.core.compiler.release=enabled | |||||
| org.eclipse.jdt.core.compiler.source=17 | |||||
| @ -0,0 +1,14 @@ | |||||
| VAMOS A CONECTARNOS CON UNA BASE DE DATOS Y VAMOS A CREAR UNA TABLA Y AÑADIREMOS UN NOMBRE | |||||
| Tendremos 2 clases la de conexion y la Main. | |||||
| La clase Conexcion hace todas la conexiones con la base de datos | |||||
| Y la Main tendra dos metodos donde el primero lo que hara es crear la base de datos y el segundo añadira los archivos a la base de datos creada anteriormente. | |||||
| ``` | |||||
| Se ha creado correctamente la tabla!! | |||||
| Se ha añadido correctamente!!! | |||||
| ``` | |||||
| @ -0,0 +1,12 @@ | |||||
| package com.cristobalbernal.Actividad9; | |||||
| import java.sql.Connection; | |||||
| public class Conexion { | |||||
| static Connection con=null; | |||||
| static String url = "jdbc:mysql://localhost:3306/"; | |||||
| static String db = "test"; | |||||
| static String driver = "com.mysql.cj.jdbc.Driver"; | |||||
| static String user = "root"; | |||||
| static String pass = ""; | |||||
| } | |||||
| @ -0,0 +1,49 @@ | |||||
| package com.cristobalbernal.Actividad9; | |||||
| import java.sql.DriverManager; | |||||
| import java.sql.SQLException; | |||||
| import java.sql.Statement; | |||||
| public class Main { | |||||
| public static void main(String[] args) { | |||||
| crearTabla(); | |||||
| insertarDatos(); | |||||
| } | |||||
| public static void crearTabla() { | |||||
| try { | |||||
| Class.forName(Conexion.driver); | |||||
| Conexion.con=DriverManager.getConnection(Conexion.url + Conexion.db, Conexion.user, Conexion.pass); | |||||
| Statement st = Conexion.con.createStatement(); | |||||
| st.executeUpdate("CREATE TABLE JuanJo (ID INT NOT NULL, Nombre VARCHAR(50) NOT NULL, APELLIDOS VARCHAR(50) NOT NULL)"); | |||||
| System.out.println("Se ha creado correctamente la tabla!!"); | |||||
| Conexion.con.close(); | |||||
| }catch (ClassNotFoundException e1) { | |||||
| e1.printStackTrace(); | |||||
| }catch (SQLException e1) { | |||||
| e1.printStackTrace(); | |||||
| } | |||||
| } | |||||
| public static void insertarDatos() { | |||||
| try { | |||||
| Class.forName(Conexion.driver); | |||||
| Conexion.con=DriverManager.getConnection(Conexion.url + Conexion.db, Conexion.user, Conexion.pass); | |||||
| Statement st = Conexion.con.createStatement(); | |||||
| st.executeUpdate("INSERT INTO `juanjo`(`ID`, `Nombre`, `APELLIDOS`) VALUES ('1','Joan','Moncho')"); | |||||
| System.out.println("Se ha añadido correctamente!!!"); | |||||
| Conexion.con.close(); | |||||
| }catch (ClassNotFoundException e1) { | |||||
| e1.printStackTrace(); | |||||
| }catch (SQLException e1) { | |||||
| e1.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @ -0,0 +1 @@ | |||||
| package com.cristobalbernal.Actividad9; | |||||
| @ -0,0 +1,10 @@ | |||||
| /** | |||||
| * | |||||
| */ | |||||
| /** | |||||
| * @author crist | |||||
| * | |||||
| */ | |||||
| module Actividad9 { | |||||
| requires java.sql; | |||||
| } | |||||