Advertisement
LeoBard0

BD

Nov 19th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.13 KB | None | 0 0
  1. package filmesCompleto;
  2. import java.sql.*;
  3. public class BD {
  4.     public Connection connection = null;
  5.     private final String DRIVER = "com.mysql.jdbc.Driver";
  6.     private final String DBNAME = "banco";
  7.     private final String URL = "jdbc:mysql://localhost:3306/"+DBNAME+"?useTimezone=true&serverTimezone=UTC";
  8.     private final String LOGIN = "root";
  9.     private final String SENHA = "";
  10.    
  11.     public boolean getConnection(){
  12.         try{
  13.             Class.forName(DRIVER);    
  14.             connection = DriverManager.getConnection(URL, LOGIN, SENHA);
  15.             System.out.println("Conectou");
  16.             return true;
  17.         }catch(ClassNotFoundException erro){
  18.             System.out.println("Driver não encontrado!\n"+erro.toString());
  19.             return false;    
  20.         }catch(SQLException erro){
  21.             System.out.println("Falha ao conectar!\n"+erro.toString());
  22.             return false;    
  23.         }
  24.     }
  25.    
  26.     public void close(){
  27.         try{
  28.             connection.close();
  29.             System.out.println("Desconectou");
  30.         }catch(SQLException erro){
  31.            
  32.         }
  33.     }
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement