Skip to content

Instantly share code, notes, and snippets.

@chukitow
Created September 29, 2014 20:59
Show Gist options
  • Save chukitow/2ade034441e523996604 to your computer and use it in GitHub Desktop.
Save chukitow/2ade034441e523996604 to your computer and use it in GitHub Desktop.
JAVA MYSQL CONNECTION
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.chukitow.ci.actions;
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author chukitow
*/
public class Dbconection {
public Dbconection()
{
}
//probando la conexion
public Connection Conectar()
{
//declarando un objeto conexion;
Connection link=null;
try
{
//cargamos el archivo de conexion
Class.forName("com.mysql.jdbc.Driver");
//creamos el enlace
link= DriverManager.getConnection("jdbc:mysql://"+Database.host+"/"+Database.db+"?user="+Database.user+"&password="+Database.password+"");
}
catch(Exception e)
{
System.err.println("Imposible database connection");
}
//retorna el link
return link;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment