Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public static HttpServletResponse getData(HttpServletResponse response)
  2. throws SQLException, InstantiationException,
  3. IllegalAccessException, ClassNotFoundException, IOException {
  4.  
  5. System.out
  6. .println("-------- MySQL JDBC Connection Testing ------------");//debug stmt
  7.  
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. } catch (ClassNotFoundException e) {
  11. System.out.println("Where is your MySQL JDBC Driver?");//debug stmt
  12. e.printStackTrace();
  13. return null;
  14. }
  15.  
  16. System.out.println("MySQL JDBC Driver Registered!");//debug stmt
  17. Connection connection = null;
  18.  
  19. try {
  20. connection = DriverManager
  21. .getConnection("jdbc:mysql://localhost:3306/DBNAME",
  22. "USERNAME", "PASSWORD");
  23.  
  24. } catch (SQLException e) {
  25. System.out.println("Connection Failed! Check output console");//debug stmt
  26. e.printStackTrace();
  27. return null;
  28. }
  29.  
  30. if (connection != null) {
  31. System.out.println("You made it, take control your database now!");//debug stmt
  32. // DB Verbindung steht: ab hier kann Programmiert werden
  33.  
  34. }
  35.  
  36. } else {// Falls die Verbindung nicht funktioniert hat
  37. System.out.println("Failed to make connection!");//debug stmt
  38. return null;
  39.  
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement