Iniciar database

This commit is contained in:
Guillermo Roche 2019-12-17 21:52:05 +01:00
parent 55ddf047a2
commit 9955ee422b
6 changed files with 60 additions and 1 deletions

View File

@ -1,6 +1,9 @@
<?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-1.8"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="mariadb-java-client-2.5.2-javadoc.jar"/>
<classpathentry kind="lib" path="mariadb-java-client-2.5.2-sources.jar"/>
<classpathentry kind="lib" path="mariadb-java-client-2.5.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

Binary file not shown.

Binary file not shown.

11
src/Main.java Normal file
View File

@ -0,0 +1,11 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
Modelo modelo = new Modelo();
}
}

45
src/Modelo.java Normal file
View File

@ -0,0 +1,45 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class Modelo {
private Connection connection;
private static final String crearDB = "create database if not exists gestionGastos;\n";
private static final String crearMes = "create table if not exists mes (\n" +
" id int primary key,\n" +
" anio int,\n" +
" mes int,\n" +
" total float\n" +
");\n";
private static final String crearGestion = "create table if not exists gestion (\n" +
" id int primary key,\n" +
" id_mes int,\n" +
" suma float,\n" +
" foreign key (id_mes) references mes(id)\n" +
");\n";
private static final String crearTranasccion = "create table if not exists transacciones (\n" +
" id int primary key,\n" +
" id_gestion int,\n" +
" dinero float,\n" +
" fecha date\n" +
");";
Modelo(){
try {
connection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/gestionGastos?user=root&password=1234");
Statement crearDB = connection.createStatement();
//crearDB.executeQuery(Modelo.scriptInicial);
crearDB.executeQuery(Modelo.crearDB);
crearDB.executeUpdate(Modelo.crearMes);
crearDB.executeUpdate(Modelo.crearGestion);
crearDB.executeUpdate(Modelo.crearTranasccion);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}