Guest User

Untitled

a guest
Mar 10th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. public class Conexion {
  2. private static Conexion instancia=null;
  3. private static Connection conn;
  4.  
  5. private Conexion()
  6. {
  7. String host="127.0.0.1:3306";
  8. String user="root";
  9. String pass="xxxx";
  10. String dtbs="bd_alumnos";
  11.  
  12. try
  13. {
  14. Class.forName("com.mysql.jdbc.Driver"); //Inicializar el driver
  15. String newConnectionURL = "jdbc:mysql://"+host+"/"+dtbs
  16. + "?" +"user=" + user + "&password=" + pass;
  17. conn = DriverManager.getConnection(newConnectionURL);
  18. }catch(Exception e)
  19. {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public static Conexion getInstancia()
  25. {
  26. if(instancia==null) instancia=new Conexion();
  27. return instancia;
  28. }
  29.  
  30. String newConnectionURL = "jdbc:mysql://"+host+"/"+dtbs
  31. + "?" +"user=" + user + "&password=" + pass;
  32.  
  33. if(instancia==null) instancia=new Conexion();
  34.  
  35. public class Conexion {
  36. private static Conexion instancia=null;
  37. private static Connection conn;
  38.  
  39. private Conexion()
  40. {
  41. String host="127.0.0.1:3306";
  42. String user="root";
  43. String pass="xxxx";
  44. String dtbs="bd_alumnos";
  45. String driver = "com.mysql.jdbc.Driver";
  46. String connection = "jdbc:mysql://"+host+"/"+dtbs;
  47.  
  48. try
  49. {
  50. Class.forName(driver);
  51. Connection conn = DriverManager.getConnection(connection, user, pass);
  52.  
  53. }catch(Exception e)
  54. {
  55. e.printStackTrace();
  56. }
  57. }
  58.  
  59. public static Conexion getInstancia()
  60. {
  61. if(instancia==null) instancia=new Conexion();
  62. return instancia;
  63. }
Add Comment
Please, Sign In to add comment