/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package database_teste; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * * @author Andre */ public class Conexao { public static Connection conexao(){ Connection connection = null; try{ // Carregando o JDBC Driver String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver Class.forName(driverName); // Criando a conexão com o Banco de Dados String serverName = "localhost"; String mydatabase = "ads_noite"; String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url String username = "root"; String password = ""; connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e ){ // Driver não encontrado System.out.println("O driver expecificado não foi encontrado."); } catch (SQLException e){ // Não está conseguindo se conectar ao banco System.out.println("Não foi possível conectar ao Banco de Dados"); } return connection; } }