Co Nectar

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

package conectar;

import com.mysql.jdbc.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class conectar {

private static Connection con;

private static final String driver="com.mysql.jdbc.Driver";

private static final String user="root";

private static final String pass="";

private static final String url="jdbc:mysql://localhost:3306/seguridad_bd";

public void conector() throws SQLException {

con=null;

try{

Class.forName(driver);

con= (Connection) DriverManager.getConnection(url, user, pass);

if (con!=null){

System.out.println("Conexion establecida");

catch (ClassNotFoundException | SQLException e){

System.out.println("Error de conexion" + e);

}
public Connection getconnection(){

return con;

public void desconectar(){

con = null;

if (con == null ){

System.err.println("conexion terminada ");

}
package conectar;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class conexion {

Connection con;

public Connection conexion () throws ClassNotFoundException, SQLException{

try{

Class.forName("com.mysql.jdbc.Driver");

con = DriverManager.getConnection("jdbc:mysql://junior-
pc/seguridad_bd","root","dain1992");

System.out.println("Conexion establecida");
}catch (SQLException e){

System.out.println(e.getMessage());

}return con;

Statement CreateStatement(){

throw new UnsupportedOperationException("no soportado");

You might also like