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 aula.facul;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- public class Conexao {
- private final String URL = "jdbc:mysql://localhost:3306/sapataria";
- private final String Driver = "org.gjt.mm.mysql.Driver";
- private final String Usuario = "root";
- private final String Senha = "";
- private static Connection Con;
- public Conexao(){
- try {
- Con = DriverManager.getConnection(URL, Usuario, Senha);
- Con.setAutoCommit(false);
- //JOptionPane.showMessageDialog(null, "Conectado com Sucesso", "Conectado", 1);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Erro ao Conectar com o Banco", "Erro", 0);
- }
- }
- public static Connection getConnection(){
- if (Con == null){
- new Conexao();
- }
- return Con;
- }
- public static void fecharConexao(){
- try {
- if (!Con.isClosed()){
- Con.close();
- }
- } catch (SQLException ex) {
- Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void main(String args[]){
- Conexao.getConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement