Advertisement
Guest User

Untitled

a guest
Mar 24th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
  2. // Load the class that provides the new "jdbc:google:mysql://" prefix.
  3. Class.forName("com.mysql.jdbc.GoogleDriver");
  4. url = "jdbc:google:mysql://my-project-id:my-instance-name/guestbook? user=root ";
  5. } else {
  6. // Local MySQL instance to use during development.
  7. Class.forName("com.mysql.jdbc.Driver");
  8. url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root password=xyz";
  9. }
  10. }
  11. } catch (Exception e) {
  12. e.printStackTrace();
  13. return;
  14. }
  15.  
  16. PrintWriter out = resp.getWriter();
  17. try {
  18. Connection conn = DriverManager.getConnection(url);
  19. try {
  20. String fname = req.getParameter("guestName");
  21. String content = req.getParameter("content");
  22. if (fname == "" || content == "") {
  23. out.println(
  24. "<html><head></head><body>You are missing either a message or a name! Try again! " +
  25. "Redirecting in 3 seconds...</body></html>");
  26. } else {
  27. String statement = "INSERT INTO entries (guestName, content) VALUES( ? , ? )";
  28. PreparedStatement stmt = conn.prepareStatement(statement);
  29. stmt.setString(1, fname);
  30. stmt.setString(2, content);
  31. int success = 2;
  32. success = stmt.executeUpdate();
  33. if (success == 1) {
  34. out.println(
  35. "<html><head></head><body>Success! Redirecting in 3 seconds...</body></html>");
  36. } else if (success == 0) {
  37. out.println(
  38. "<html><head></head><body>Failure! Please try again! " +
  39. "Redirecting in 3 seconds...</body></html>");
  40. }
  41. }
  42. } finally {
  43. conn.close();
  44. }
  45. } catch (SQLException e) {
  46. e.printStackTrace();
  47. }
  48. resp.setHeader("Refresh", "3; url=/guestbook.jsp");
  49.  
  50. HTTP ERROR 500
  51. Problem accessing /guestbook.jsp. Reason:
  52. java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
  53. Caused by:javax.servlet.ServletException: java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement