Advertisement
Guest User

Conetion jdbc

a guest
Apr 12th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class MyDataAcces {
  8.  
  9. private String _usuario="root";
  10. private String _pwd= "root";
  11. private static String _bd="empresa";
  12. static String _url = "jdbc:mysql://localhost/"+_bd;
  13. private Connection conn = null;
  14.  
  15. public MyDataAcces() {
  16.  
  17. try{
  18. Class.forName("com.mysql.jdbc.Connection");
  19. conn = (Connection)DriverManager.getConnection(_url, _usuario, _pwd);
  20. if(conn != null)
  21. {
  22. System.out.println("Conexi-n a base de datos "+_url+" . . . Ok");
  23. }
  24. }
  25. catch(SQLException ex)
  26. {
  27. System.out.println("Hubo un problema al intentar conecarse a la base de datos"+_url);
  28. }
  29. catch(ClassNotFoundException ex)
  30. {
  31. System.out.println(ex);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement