Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projetofinal;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class ConexaoMysql {
- public ConexaoMysql() {
- }
- public static java.sql.Connection getConexaoMySQL() {
- try {
- String driverName = "com.mysql.jdbc.Driver";
- Class.forName(driverName);
- Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/projetofinal", "root", "root");
- System.out.println("Conexao Bem Sucedida");
- return connection;
- } catch (ClassNotFoundException e) {
- System.out.println("O driver expecificado nao foi encontrado.");
- return null;
- } catch (SQLException e) {
- System.out.println("Nao foi possivel conectar ao Banco de Dados.");
- return null;
- }
- }
- public static boolean FecharConexao() {
- try {
- ConexaoMysql.getConexaoMySQL().close();
- return true;
- } catch (SQLException e) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement