0

使用 netbeans 我创建了一个 web 应用程序,带有提交按钮的 html 表单导致一个 servlet。我想打印我的 derby db 的结果。目前,当我运行它时,html 页面加载正常,但此 servlet 的提交链接给出“SQLException 捕获:发生连接身份验证失败。原因:用户 ID 或密码无效。” 我检查了数据库凭据,用户是正确的,并且密码被记住了。

请参阅下面的 servlet 代码

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, ClassNotFoundException, SQLException {
        Connection con = null;
       Statement stmt = null;
       ResultSet rs = null;

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            con = DriverManager.getConnection("jdbc:derby://localhost:1527/movies;user=tb");
            stmt = con.createStatement();

        rs = stmt.executeQuery("SELECT * FROM TB.MOVIES");

        while (rs.next()) {
        String s = rs.getString("TITLE");
        //float n = rs.getFloat("Age");
        out.println(s + "   ");
        }

            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet NewServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
        catch(ClassNotFoundException e)

        {

          out.println("Couldn't load database driver: " + e.getMessage());

        }

      catch(SQLException e)

        {

          out.println("SQLException caught : " + e.getMessage());

        }
        finally {            
            out.close();
4

0 回答 0