Skip to content

Instantly share code, notes, and snippets.

@chukitow
Created December 10, 2013 17:03
Show Gist options
  • Save chukitow/7894128 to your computer and use it in GitHub Desktop.
Save chukitow/7894128 to your computer and use it in GitHub Desktop.
Clase para la conexion a una base de datos sqlite
import java.awt.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
/**
*
* @author chukitow
*/
public class Dbconection {
public String db="sistema.sqlite"; //Nombre de la base de datos
public String url="jdbc:sqlite::resource:config/"+db; //Direccion, la misma por defecto siempre
public String user="root"; //usuario
public String pass=""; // contraseña
private Component rootPane;
//probando la conexion
public Connection Conectar()
{
//declarando un objeto conexion;
Connection link=null;
try
{
//cargamos el archivo de conexion
Class.forName("org.sqlite.JDBC");
//creamos el enlace
link= DriverManager.getConnection(this.url,this.user,this.pass);
}
catch(Exception e)
{
//Encaso de no haber logrado conectividad
JOptionPane.showMessageDialog(null, e);
}
//retorna el link
return link;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment