Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FactoryCon {
- private static Connection con;
- public static Connection getConection(){
- try{
- //Está é a forma de verifcar se já existe conexão se
- //for "vazio" ele cria se não ele só retorna a
- //a conexão aberta.
- if(con == null){
- Class.forName( "com.mysql.jdbc.Driver" ); // Conexão com o banco
- String url = "jdbc:mysql://127.0.0.1:3306/headquarter";
- String user = "root";
- String password = "Irlanzinhobr2";
- con = DriverManager.getConnection(url,user,password); // Conexão com o banco
- return con;
- }else{
- return con; //Retorna a conexão existente.
- }
- }
- //Depois do uso do Throw o erro no retorno foi resolvido.
- catch(SQLException | ClassNotFoundException e){ //Exceção generica.
- JOptionPane.showMessageDialog(null,"Error na classe FactoryCon: "+ e.getMessage());
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement