Browse Source

Commit

master
Cristobal 2 years ago
commit
efe647ebe7
13 changed files with 130 additions and 0 deletions
  1. +11
    -0
      .classpath
  2. +17
    -0
      .project
  3. +2
    -0
      .settings/org.eclipse.core.resources.prefs
  4. +14
    -0
      .settings/org.eclipse.jdt.core.prefs
  5. +14
    -0
      README.md
  6. BIN
      bin/com/cristobalbernal/Actividad9/Conexion.class
  7. BIN
      bin/com/cristobalbernal/Actividad9/Main.class
  8. BIN
      bin/com/cristobalbernal/Actividad9/package-info.class
  9. BIN
      bin/module-info.class
  10. +12
    -0
      src/com/cristobalbernal/Actividad9/Conexion.java
  11. +49
    -0
      src/com/cristobalbernal/Actividad9/Main.java
  12. +1
    -0
      src/com/cristobalbernal/Actividad9/package-info.java
  13. +10
    -0
      src/module-info.java

+ 11
- 0
.classpath View File

@ -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>

+ 17
- 0
.project View File

@ -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>

+ 2
- 0
.settings/org.eclipse.core.resources.prefs View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

+ 14
- 0
.settings/org.eclipse.jdt.core.prefs View File

@ -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

+ 14
- 0
README.md View File

@ -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!!!
```

BIN
bin/com/cristobalbernal/Actividad9/Conexion.class View File


BIN
bin/com/cristobalbernal/Actividad9/Main.class View File


BIN
bin/com/cristobalbernal/Actividad9/package-info.class View File


BIN
bin/module-info.class View File


+ 12
- 0
src/com/cristobalbernal/Actividad9/Conexion.java View File

@ -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 = "";
}

+ 49
- 0
src/com/cristobalbernal/Actividad9/Main.java View File

@ -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();
}
}
}

+ 1
- 0
src/com/cristobalbernal/Actividad9/package-info.java View File

@ -0,0 +1 @@
package com.cristobalbernal.Actividad9;

+ 10
- 0
src/module-info.java View File

@ -0,0 +1,10 @@
/**
*
*/
/**
* @author crist
*
*/
module Actividad9 {
requires java.sql;
}

Loading…
Cancel
Save