Advertisement
eletrico123

Untitled

Nov 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. package conexao;
  2. import java.sql.*;
  3. public class ModuloConexao {
  4.     //método responsável por estabelecer conexão com o BD
  5.     public static Connection Conector() {
  6.         java.sql.Connection conexao = null;
  7.         //a linha abaixo "chama" o driver
  8.         String driver = "com.mysql.jdbc.Driver";
  9.         //Armazenando informações referente ao banco
  10.         //String url = "jdbc:mysql://localhost:3306/dbinfox";
  11.         String url = "jdbc:mysql://localhost/simulado1?autoReconnect=true&useSSL=false";
  12.         String user = "root";
  13.         String password = "";
  14.         //Estabelecendo a conexão com o banco
  15.         try {
  16.             //Class.forName(driver);
  17.             conexao = DriverManager.getConnection(url, user, password);
  18.             //System.out.println("Conexão com Sucesso");
  19.             return conexao;
  20.         } catch (Exception e) {
  21.             //a linha abaixo serve de apoio para esclarecer o erro
  22.             System.err.println("\n============================================");
  23.             System.err.println("\nCLASSE VISITAS CONECTA BANCO");
  24.             System.err.println("\nERRO NO MÉTODO GET CONNECTION");
  25.             System.err.println("\n " + e.getCause());
  26.             System.err.println("\n " + e.getMessage());
  27.             System.err.println("\n============================================");
  28.             throw new RuntimeException(e);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement