Last active
November 27, 2018 20:21
-
-
Save jeffersontpadua/e4d8cac9b300782e8e72c85756931890 to your computer and use it in GitHub Desktop.
Conexão com MySQL em Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author JEFFERSON | |
*/ | |
public class ConexaoMySQL { | |
private String usuario; | |
private String senha; | |
private String banco; | |
public ConexaoMySQL(String usuario, String senha, String banco) { | |
this.usuario = usuario; | |
this.senha = senha; | |
this.banco = banco; | |
} | |
public Connection getConexao() { | |
try { | |
return DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/" + banco, usuario, senha); | |
} catch (SQLException ex) { | |
Logger.getLogger(ConexaoMySQL.class.getName()).log(Level.SEVERE, null, ex); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment