Guest User

Untitled

a guest
Jan 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. Tengo esta clase. Armo dos conexiones porque tiene que crear una database dinámica a partir de datos que le tire el usuario. Pero eso entra después.
  2.  
  3.  
  4. package classcreator.DB;
  5.  
  6. import classcreator.ClassCreator;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. public class DataBaseConnFactory {
  13.  
  14. private static DataBaseConnFactory instance = new DataBaseConnFactory();
  15. private String userName;
  16. private String MySQLurl;
  17. private String password = "";
  18.  
  19. static {
  20. try {
  21. Class.forName("com.mysql.jdbc.Driver");
  22. } catch (ClassNotFoundException ex) {
  23. Logger.getLogger(DataBaseConnFactory.class.getName()).log(Level.SEVERE, null, ex);
  24. }
  25. }
  26.  
  27. public void assignValues(String url) {
  28. this.userName = "root";
  29. this.MySQLurl = "jdbc:mysql:localhost/" + url;
  30. }
  31.  
  32. public static DataBaseConnFactory getInstance() {
  33. return DataBaseConnFactory.instance;
  34. }
  35.  
  36. public Connection obtenerConnexion() throws Exception {
  37. assignValues("test");
  38. Connection connection = null;
  39. connection = DriverManager.getConnection(this.MySQLurl, userName, password);
  40. return connection;
  41. }
  42.  
  43. public Connection obtenerNewConexion() throws Exception {
  44. assignValues(ClassCreator.getInstance().getPackagename());
  45. Connection connection = DriverManager.getConnection(this.MySQLurl, userName, password);
  46. return connection;
  47. }
  48. }
  49.  
  50.  
  51. Cuando busco la conexión y le tiro una query cualquiera me salta este error.
  52.  
  53. java.sql.SQLException: No suitable driver found for jdbc:mysql:localhost/test
  54.  
  55. Ya he probado cambiarle el nombre del driver, fijarme en poner el url como IP, ponerle el puerto y todo y nada.
  56. Ideas?
Add Comment
Please, Sign In to add comment