This commit is contained in:
@@ -10,4 +10,11 @@
|
|||||||
<maven.compiler.release>25</maven.compiler.release>
|
<maven.compiler.release>25</maven.compiler.release>
|
||||||
<exec.mainClass>com.mycompany.programasqlite.Programasqlite</exec.mainClass>
|
<exec.mainClass>com.mycompany.programasqlite.Programasqlite</exec.mainClass>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xerial</groupId>
|
||||||
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
|
<version>3.41.2.1</version> <!-- Use the latest version available -->
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,13 +4,24 @@
|
|||||||
|
|
||||||
package com.mycompany.programasqlite;
|
package com.mycompany.programasqlite;
|
||||||
|
|
||||||
|
import controlador.Controlador;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import modelo.ModeloBD;
|
||||||
|
import vista.Vista;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author antonio
|
* @author antonio
|
||||||
*/
|
*/
|
||||||
public class Programasqlite {
|
public class Programasqlite {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws SQLException {
|
||||||
System.out.println("Hello World!");
|
ModeloBD modelo=new ModeloBD();
|
||||||
}
|
Vista vista=new Vista();
|
||||||
|
Controlador programa=new Controlador(modelo,vista);
|
||||||
|
programa.iniciar();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,19 +12,19 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
import modelo.Modelo;
|
import modelo.ModeloBD;
|
||||||
import vista.Vista;
|
import vista.Vista;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author antonio
|
* @author antonio
|
||||||
*/
|
*/
|
||||||
public abstract class Controlador implements ActionListener, WindowListener
|
public class Controlador implements ActionListener, WindowListener
|
||||||
{
|
{
|
||||||
private final Modelo modelo;
|
private final ModeloBD modelo;
|
||||||
private final Vista vista;
|
private final Vista vista;
|
||||||
|
|
||||||
public Controlador(Modelo _modelo, Vista _vista)
|
public Controlador(ModeloBD _modelo, Vista _vista)
|
||||||
{
|
{
|
||||||
this.modelo = _modelo;
|
this.modelo = _modelo;
|
||||||
this.vista = _vista;
|
this.vista = _vista;
|
||||||
@@ -75,7 +75,8 @@ public abstract class Controlador implements ActionListener, WindowListener
|
|||||||
}
|
}
|
||||||
public void iniciar()
|
public void iniciar()
|
||||||
{
|
{
|
||||||
if (modelo.checkConnection())
|
modelo.connect();
|
||||||
|
if (modelo.conectado())
|
||||||
{
|
{
|
||||||
modelo.printConnectionStatus();
|
modelo.printConnectionStatus();
|
||||||
vista.setTitle("TO-DO APP");
|
vista.setTitle("TO-DO APP");
|
||||||
@@ -96,6 +97,8 @@ public abstract class Controlador implements ActionListener, WindowListener
|
|||||||
@Override public void windowDeiconified(WindowEvent e) { System.out.println("Restaurada"); }
|
@Override public void windowDeiconified(WindowEvent e) { System.out.println("Restaurada"); }
|
||||||
@Override public void windowActivated(WindowEvent e) { System.out.println("Activada"); }
|
@Override public void windowActivated(WindowEvent e) { System.out.println("Activada"); }
|
||||||
@Override public void windowDeactivated(WindowEvent e) { System.out.println("Desactivada"); }
|
@Override public void windowDeactivated(WindowEvent e) { System.out.println("Desactivada"); }
|
||||||
|
@Override public void windowClosing(WindowEvent e) {System.out.println("Desactivada"); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.
@@ -64,6 +64,9 @@
|
|||||||
</Table>
|
</Table>
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<AuxValues>
|
||||||
|
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
|
||||||
|
</AuxValues>
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ public class Vista extends javax.swing.JFrame
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||||
private void initComponents()
|
private void initComponents() {
|
||||||
{
|
|
||||||
|
|
||||||
jScrollPane1 = new javax.swing.JScrollPane();
|
jScrollPane1 = new javax.swing.JScrollPane();
|
||||||
jTable1 = new javax.swing.JTable();
|
jTable1 = new javax.swing.JTable();
|
||||||
@@ -39,15 +38,13 @@ public class Vista extends javax.swing.JFrame
|
|||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
jTable1.setModel(new javax.swing.table.DefaultTableModel(
|
||||||
new Object [][]
|
new Object [][] {
|
||||||
{
|
|
||||||
{null, null, null, null},
|
{null, null, null, null},
|
||||||
{null, null, null, null},
|
{null, null, null, null},
|
||||||
{null, null, null, null},
|
{null, null, null, null},
|
||||||
{null, null, null, null}
|
{null, null, null, null}
|
||||||
},
|
},
|
||||||
new String []
|
new String [] {
|
||||||
{
|
|
||||||
"Title 1", "Title 2", "Title 3", "Title 4"
|
"Title 1", "Title 2", "Title 3", "Title 4"
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@@ -131,6 +128,6 @@ public class Vista extends javax.swing.JFrame
|
|||||||
private javax.swing.JButton jButton1;
|
private javax.swing.JButton jButton1;
|
||||||
private javax.swing.JPanel jPanel1;
|
private javax.swing.JPanel jPanel1;
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
private javax.swing.JTable jTable1;
|
public javax.swing.JTable jTable1;
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
}
|
}
|
||||||
|
|||||||
0
programasqlite/todo.db
Normal file
0
programasqlite/todo.db
Normal file
0
programasqlite/your_database.db
Normal file
0
programasqlite/your_database.db
Normal file
Reference in New Issue
Block a user