Advertisement
Guest User

Untitled

a guest
Oct 4th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class ConexaoBD {
  6. // Define o Metodo de Conexao quando a classe � chamada
  7. static {
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException e) {
  11. throw new RuntimeException(e);
  12. }
  13. }
  14.  
  15. public Connection obtemConexao() throws SQLException{
  16. System.getProperties().setProperty("javax.net.ssl.trustStore","/mysqlcertificate.pem");
  17. return DriverManager.getConnection(
  18. "jdbc:mysql://myHost",
  19. "myUsername",
  20. "myPassword");
  21. }
  22.  
  23. }
  24.  
  25. Connection conn = null;
  26. Statement stm = null;
  27. try {
  28. ConexaoBD bd = new ConexaoBD();
  29. conn = bd.obtemConexao();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement