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