Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/database_name..
  2.  
  3. // JDBC driver name and database URL
  4. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  5. static final String DB_URL = "jdbc:mysql://localhost:3306/program1";
  6.  
  7. // Database credentials
  8. static final String USER = "user";
  9. static final String PASS = "pass";
  10.  
  11. private static Connection conn = null;
  12.  
  13.  
  14. /*
  15. * Create connection to the DB in singletone
  16. * */
  17. protected static Connection getConnection() throws ClassNotFoundException, SQLException
  18. {
  19. if(conn==null)
  20. {
  21. try
  22. {
  23. // Register JDBC driver
  24. //Class.forName(JDBC_DRIVER);
  25.  
  26. // Open connection
  27. conn = DriverManager.getConnection(DB_URL,USER,PASS);
  28. }
  29. catch ( SQLException e) {
  30. // TODO Auto-generated catch block
  31. e.printStackTrace();
  32. if(conn != null)
  33. conn.close();
  34. }
  35. }
  36.  
  37. return conn;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement