This commit is contained in:
@@ -1,14 +1,51 @@
|
|||||||
/*
|
|
||||||
* 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;
|
package modelo;
|
||||||
|
|
||||||
/**
|
import java.sql.Connection;
|
||||||
*
|
import java.sql.DriverManager;
|
||||||
* @author antonio
|
import java.sql.SQLException;
|
||||||
*/
|
|
||||||
public class Modelo
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user