Guest User

Untitled

a guest
Aug 26th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;
  2. import java.sql.Connection;
  3. import java.sql.SQLException;
  4. import javax.sql.DataSource;
  5. import javax.swing.JOptionPane;
  6.  
  7. class ManejadorConexiones {
  8. public static ManejadorConexiones Conexion = null;
  9. public DataSource ds;
  10. public Connection con;
  11. private String pass;
  12. public ManejadorConexiones(){
  13. pass = null;
  14. ds = null;
  15. }
  16. public DataSource CrearConexion() {
  17. try{
  18. MysqlConnectionPoolDataSource dso = new MysqlConnectionPoolDataSource();
  19. String stDatabaseName = "musica";
  20. String stPort = "3306";
  21. String userName = "root";
  22. if(pass == null){
  23. pass = "troLOL93";
  24. }
  25. String password = pass;
  26. String stHost = "localhost";
  27. dso.setDatabaseName(stDatabaseName);
  28. dso.setPort(Integer.parseInt(stPort));
  29. dso.setUser(userName);
  30. dso.setPassword(password);
  31. dso.setServerName(stHost);
  32. ds = dso;
  33. }
  34. catch(Exception e){}
  35. return ds;
  36. }
  37.  
  38. public static ManejadorConexiones getInstance(){
  39. if(Conexion == null){
  40. Conexion = new ManejadorConexiones();
  41. }
  42. return Conexion;
  43. }
  44.  
  45. public Connection getConn() throws SQLException {
  46. return ds.getConnection();
  47. }
  48.  
  49. public DataSource getDataSource(){
  50. return ds;
  51. }
  52. }
Add Comment
Please, Sign In to add comment