Created
December 10, 2013 17:03
-
-
Save chukitow/7894128 to your computer and use it in GitHub Desktop.
Clase para la conexion a una base de datos sqlite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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