Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  2. {
  3. response.setContentType("text/html;charset=UTF-8");
  4. try (PrintWriter out = response.getWriter())
  5. {
  6. Connection c = MySQLConnector.connect("DBFoobar", "username", "passwd");
  7. String message = null;
  8. if (c == null)
  9. message = "Connection returned null";
  10. else
  11. message = "C is returned: " + c.toString();
  12. out.println("<!DOCTYPE html>");
  13. out.println("<html>");
  14. out.println("<body>");
  15. out.println(message);
  16. .
  17. .
  18. .
  19.  
  20. public class MySQLConnector
  21. {
  22. private static final String dbURLPrefix
  23. = "jdbc:mysql://dbfoobar.xxx.uswest2.rds.amazonaws.com:3306/";
  24. public static Connection connect(String dbName, String username, String password)
  25. {
  26. Connection connection = null;
  27. try
  28. {
  29. Class.forName("com.mysql.jdbc.Driver");
  30. connection = DriverManager.getConnection(dbURLPrefix + dbName
  31. + "?useUnicode=yes&characterEncoding=UTF-8&useSSL=false", username, password);
  32. .
  33. .
  34. .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement