Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.com.ConexaoBanco;
- /**
- *
- * @author hotsystems
- */
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class ConexaoMySQL {
- public static String status = "Não conectou...";
- public ConexaoMySQL() {
- }
- public static java.sql.Connection getConexaoMySQL() {
- Connection connection = null; //atributo do tipo Connection
- try {
- String driverName = "com.mysql.jdbc.Driver";
- Class.forName(driverName);
- String serverName = "";
- String mydatabase ="";
- String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
- String username = "";
- String password = "";
- connection = DriverManager.getConnection(url, username, password);
- //Testa sua conexão//
- if (connection != null) {
- status = ("STATUS--->Conectado com sucesso!");
- } else {
- status = ("STATUS--->Não foi possivel realizar conexão");
- }
- return connection;
- } catch (ClassNotFoundException e) {
- System.out.println("O driver do banco de dados nao foi encontrado.");
- return null;
- } catch (SQLException e) {
- System.out.println(e);
- System.out.println("Nao foi possivel conectar ao Banco de Dados.");
- return null;
- }
- }
- public static String statusConection() {
- return status;
- }
- public static boolean FecharConexao() {
- try {
- ConexaoMySQL.getConexaoMySQL().close();
- return true;
- } catch (SQLException e) {
- return false;
- }
- }
- public static java.sql.Connection ReiniciarConexao() {
- FecharConexao();
- return ConexaoMySQL.getConexaoMySQL();
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package controlesincronismo;
- import br.com.ConexaoBanco.ConexaoMySQL;
- /**
- *
- * @author hotsystems
- */
- public class ControleSincronismo {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- ConexaoMySQL con = new ConexaoMySQL();
- con.getConexaoMySQL();
- con.statusConection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement