This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
package modelo;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Modelo
|
||||
{
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Modelo()
|
||||
{
|
||||
connect();
|
||||
}
|
||||
|
||||
private void connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
// creamos la url deconexión
|
||||
String url = "jdbc:sqlite:todo.db"; // se puede usar el nombre la ruta o memory (volatil)
|
||||
// creamos la conexión usando la url anterior
|
||||
connection = DriverManager.getConnection(url);
|
||||
|
||||
System.out.println("Todo ha ido bien!!!");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkConnection()
|
||||
{
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
// Establece el estado actual de la conexión
|
||||
public void printConnectionStatus()
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
System.out.println("Database connection is active.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Database connection is not established.");
|
||||
}
|
||||
}
|
||||
}
|
||||
166
programasqlite/src/main/java/modelo/ModeloBD.java
Normal file
166
programasqlite/src/main/java/modelo/ModeloBD.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package modelo;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class ModeloBD
|
||||
{
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public ModeloBD() throws SQLException
|
||||
{
|
||||
connection=null;
|
||||
connect();
|
||||
borrartabla();
|
||||
crearTablaSiNoEstaCreada();
|
||||
insertardatosinicialesinventados();
|
||||
|
||||
}
|
||||
|
||||
public void connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
// creamos la url deconexión
|
||||
String url = "jdbc:sqlite:/home/antonio/NetBeansProjects/Unidad1/programasqlite/src/main/java/modelo/todo.db"; // se puede usar el nombre la ruta o memory (volatil)
|
||||
// creamos la conexión usando la url anterior
|
||||
connection = DriverManager.getConnection(url);
|
||||
|
||||
System.out.println("Todo ha ido bien!!!");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean conectado()
|
||||
{
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
// Establece el estado actual de la conexión
|
||||
public void printConnectionStatus()
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
System.out.println("Database connection is active.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Database connection is not established.");
|
||||
}
|
||||
}
|
||||
public ResultSet getTasks()
|
||||
{
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
String query = "SELECT * FROM todo";
|
||||
rs = connection.createStatement().executeQuery(query);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
return rs;
|
||||
|
||||
}
|
||||
|
||||
private void crearTablaSiNoEstaCreada() throws SQLException
|
||||
{
|
||||
String sentencia="CREATE TABLE IF NOT EXISTS todo (\n" +
|
||||
" id INTEGER PRIMARY KEY AUTOINCREMENT, -- Identificador único\n" +
|
||||
" title TEXT NOT NULL, -- Título corto de la tarea\n" +
|
||||
" description TEXT, -- Descripción opcional\n" +
|
||||
" is_done INTEGER NOT NULL DEFAULT 0, -- 0 = pendiente, 1 = completada\n" +
|
||||
" priority INTEGER DEFAULT 0, -- 0=baja, 1=media, 2=alta (tu propia convención)\n" +
|
||||
" due_date TEXT, -- Fecha límite en ISO-8601, p.ej. '2025-10-13' o '2025-10-13T17:00:00'\n" +
|
||||
" created_at TEXT NOT NULL DEFAULT (datetime('now')), -- Fecha de creación (UTC)\n" +
|
||||
" updated_at TEXT -- Última actualización (UTC)\n" +
|
||||
");";
|
||||
try
|
||||
{
|
||||
if (!this.conectado())
|
||||
this.connect();
|
||||
Statement st=this.connection.createStatement();
|
||||
st.execute(sentencia);
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
System.out.println(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void borrartabla()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.conectado())
|
||||
{
|
||||
Statement st = connection.createStatement();
|
||||
String dropTableSQL = "DROP TABLE IF EXISTS todo";
|
||||
st.execute(dropTableSQL);
|
||||
System.out.println("Tabla Borrada.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("no se puede borrar la tabla: la conexión no está activa.");
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void insertardatosinicialesinventados()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.conectado())
|
||||
{
|
||||
Statement st = connection.createStatement();
|
||||
String sentencia="INSERT INTO todo (title, description, priority, due_date, is_done)\n" +
|
||||
"VALUES\n" +
|
||||
" ('Comprar leche', 'Entera, 2L', 0, '2025-10-13', 1),\n" +
|
||||
" ('Enviar informe mensual', 'Enviar por email a dirección', 1, '2025-10-14', 0),\n" +
|
||||
" ('Revisar código MVC', 'Refactor del controlador', 2, '2025-10-15', 0),\n" +
|
||||
" ('Pagar recibo de luz', 'Antes del día 15', 0, '2025-10-16', 0),\n" +
|
||||
" ('Llamar al dentista', 'Pedir cita revisión', 1, '2025-10-17', 1),\n" +
|
||||
" ('Planificar examen DAM', 'Temas de sistemas y redes', 2, '2025-10-18', 0),\n" +
|
||||
" ('Backup base de datos', 'Verificar integridad', 0, '2025-10-19', 0),\n" +
|
||||
" ('Actualizar NetBeans', 'Comprobar plugins', 1, '2025-10-20', 0),\n" +
|
||||
" ('Leer artículo sobre SQLite', 'Notas y ejemplos', 2, '2025-10-21', 1),\n" +
|
||||
" ('Hacer limpieza escritorio', 'Archivos temporales', 0, '2025-10-22', 0),\n" +
|
||||
" ('Preparar presentación Swing', 'Con demos y ejemplos', 1, '2025-10-23', 0),\n" +
|
||||
" ('Corregir prácticas', 'Grupo 2º SMR', 2, '2025-10-24', 0),\n" +
|
||||
" ('Configurar CI/CD', 'Pipeline con GitHub Actions', 0, '2025-10-25', 1),\n" +
|
||||
" ('Revisar rúbricas', 'Criterios de evaluación', 1, '2025-10-26', 0),\n" +
|
||||
" ('Actualizar currículo', 'LOMLOE Andalucía', 2, '2025-10-27', 0),\n" +
|
||||
" ('Hacer pedido de material', 'Rotuladores y papel', 0, '2025-10-28', 0),\n" +
|
||||
" ('Probar JColorChooser', 'Demostración de colores', 1, '2025-10-29', 1),\n" +
|
||||
" ('Diseñar interfaz login', 'Usuario y contraseña', 2, '2025-10-30', 0),\n" +
|
||||
" ('Revisar tests unitarios', 'Cobertura > 80%', 0, '2025-10-31', 0),\n" +
|
||||
" ('Documentar API', 'Endpoints y modelos', 1, '2025-11-01', 0);";
|
||||
st.execute(sentencia);
|
||||
|
||||
|
||||
|
||||
System.out.println("Datos iniciales insertados correctamente.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("No se pueden insertar datos iniciales: la conexión no está activa.");
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
System.out.println("Error al insertar datos iniciales: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
113
programasqlite/src/main/java/modelo/ModeloTask.java
Normal file
113
programasqlite/src/main/java/modelo/ModeloTask.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package modelo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author antonio
|
||||
*/
|
||||
public class ModeloTask
|
||||
{
|
||||
private int id;
|
||||
private String nombre;
|
||||
private String descripcion;
|
||||
private int isdone;
|
||||
private String fechalim;
|
||||
private String fechacrea;
|
||||
private String fechaactu;
|
||||
|
||||
public ModeloTask()
|
||||
{
|
||||
this.id = 0;
|
||||
this.nombre = "";
|
||||
this.descripcion = "";
|
||||
this.isdone = 0;
|
||||
this.fechalim = "";
|
||||
this.fechacrea = "";
|
||||
this.fechaactu = "";
|
||||
}
|
||||
|
||||
public ModeloTask(int id, String nombre, String descripcion, int isdone, String fechalim, String fechacrea, String fechaactu)
|
||||
{
|
||||
this.id = id;
|
||||
this.nombre = nombre;
|
||||
this.descripcion = descripcion;
|
||||
this.isdone = isdone;
|
||||
this.fechalim = fechalim;
|
||||
this.fechacrea = fechacrea;
|
||||
this.fechaactu = fechaactu;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNombre()
|
||||
{
|
||||
return nombre;
|
||||
}
|
||||
|
||||
public void setNombre(String nombre)
|
||||
{
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public String getDescripcion()
|
||||
{
|
||||
return descripcion;
|
||||
}
|
||||
|
||||
public void setDescripcion(String descripcion)
|
||||
{
|
||||
this.descripcion = descripcion;
|
||||
}
|
||||
|
||||
public int getIsdone()
|
||||
{
|
||||
return isdone;
|
||||
}
|
||||
|
||||
public void setIsdone(int isdone)
|
||||
{
|
||||
this.isdone = isdone;
|
||||
}
|
||||
|
||||
public String getFechalim()
|
||||
{
|
||||
return fechalim;
|
||||
}
|
||||
|
||||
public void setFechalim(String fechalim)
|
||||
{
|
||||
this.fechalim = fechalim;
|
||||
}
|
||||
|
||||
public String getFechacrea()
|
||||
{
|
||||
return fechacrea;
|
||||
}
|
||||
|
||||
public void setFechacrea(String fechacrea)
|
||||
{
|
||||
this.fechacrea = fechacrea;
|
||||
}
|
||||
|
||||
public String getFechaactu()
|
||||
{
|
||||
return fechaactu;
|
||||
}
|
||||
|
||||
public void setFechaactu(String fechaactu)
|
||||
{
|
||||
this.fechaactu = fechaactu;
|
||||
}
|
||||
|
||||
}
|
||||
BIN
programasqlite/src/main/java/modelo/todo.db
Normal file
BIN
programasqlite/src/main/java/modelo/todo.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user