Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
- // Load the class that provides the new "jdbc:google:mysql://" prefix.
- Class.forName("com.mysql.jdbc.GoogleDriver");
- url = "jdbc:google:mysql://my-project-id:my-instance-name/guestbook? user=root ";
- } else {
- // Local MySQL instance to use during development.
- Class.forName("com.mysql.jdbc.Driver");
- url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root password=xyz";
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- PrintWriter out = resp.getWriter();
- try {
- Connection conn = DriverManager.getConnection(url);
- try {
- String fname = req.getParameter("guestName");
- String content = req.getParameter("content");
- if (fname == "" || content == "") {
- out.println(
- "<html><head></head><body>You are missing either a message or a name! Try again! " +
- "Redirecting in 3 seconds...</body></html>");
- } else {
- String statement = "INSERT INTO entries (guestName, content) VALUES( ? , ? )";
- PreparedStatement stmt = conn.prepareStatement(statement);
- stmt.setString(1, fname);
- stmt.setString(2, content);
- int success = 2;
- success = stmt.executeUpdate();
- if (success == 1) {
- out.println(
- "<html><head></head><body>Success! Redirecting in 3 seconds...</body></html>");
- } else if (success == 0) {
- out.println(
- "<html><head></head><body>Failure! Please try again! " +
- "Redirecting in 3 seconds...</body></html>");
- }
- }
- } finally {
- conn.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- resp.setHeader("Refresh", "3; url=/guestbook.jsp");
- HTTP ERROR 500
- Problem accessing /guestbook.jsp. Reason:
- java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
- 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