Guest User

Untitled

a guest
Jun 21st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;;
  4.  
  5. public class Conexao {
  6. public Connection conectar () {
  7. String url = "jdbc:mysql://localhost/godim";
  8. String usuario = "root";
  9. String senha = "010203";
  10.  
  11. try {
  12. Class.forName("com.mysql.jdbc.Driver").newInstance();
  13. Connection conn = DriverManager.getConnection(url, usuario, senha);
  14. if (conn != null)
  15. System.out.println("Conexao estabelecida");
  16. else
  17. System.out.println("Problemas!");
  18. return conn;
  19. } catch (SQLException ex) {
  20. System.out.println("SQLException: " + ex.getMessage());
  21. return null;
  22. } catch (Exception e) {
  23. System.out.println("Problemas ao tentar conectar com o banco de dados: " + e);
  24. return null;
  25. }
  26.  
  27. }
  28. }
Add Comment
Please, Sign In to add comment