Advertisement
Guest User

Untitled

a guest
Apr 21st, 2016
90
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 MySqlConnection {
  2.  
  3. private String user;
  4. private String pwd;
  5. private String url;
  6.  
  7. public MySqlConnection() {
  8. Properties p = new Properties();
  9.  
  10. try {
  11. p.load(this.getClass().getClassLoader()
  12. .getResourceAsStream("database_infos.properties"));
  13. this.user = p.getProperty("USER");
  14. this.pwd = p.getProperty("PASSWORD");
  15. this.url = p.getProperty("URL");
  16. } catch (IOException ex) {
  17. ex.printStackTrace();
  18. }
  19. }
  20.  
  21.  
  22. public static void main(String[] args) {
  23. MySqlConnection mysqlConn = new MySqlConnection();
  24. Connection conn = null;
  25.  
  26. try {
  27. Class.forName("com.mysql.jdbc.Driver").newInstance();
  28. System.out.println("Driver load");
  29. conn = DriverManager.getConnection(mysqlConn.url, mysqlConn.user, mysqlConn.pwd);
  30.  
  31. } catch (ClassNotFoundException | SQLException e) {
  32. e.printStackTrace();
  33. } catch (InstantiationException ex) {
  34. Logger.getLogger(MySqlConnection.class.getName()).log(Level.SEVERE, null, ex);
  35. } catch (IllegalAccessException ex) {
  36. Logger.getLogger(MySqlConnection.class.getName()).log(Level.SEVERE, null, ex);
  37. }
  38. }
  39.  
  40. Driver load
  41. java.sql.SQLException: No suitable driver found for "jdbc:mysql://localhost:3306/BookManager"
  42. at java.sql.DriverManager.getConnection(DriverManager.java:689)
  43. at java.sql.DriverManager.getConnection(DriverManager.java:247)
  44. at mysqlconnection.MySqlConnection.main(MySqlConnection.java:53)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement