Update Query在JSP中不起作用

时间:2015-10-13 16:37:25

标签: java sql database jsp derby

html页面如下

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    valid user 
    <form action="neww.jsp">
        name <input type="text" name="txt1">
        new pass <input type="text" name="tt">

        <input type="submit">
    </form>
</body>

enter image description here

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Statement"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            try {
                String n = request.getParameter("txt1");
                String p = request.getParameter("tt");
                Class.forName("org.apache.derby.jdbc.ClientDriver");
                Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/newtp", "root", "root");
                Statement stmt = con.createStatement();
                
                stmt.executeUpdate("update TP set PASS='" + p + "' where NAME='" + n + "' ");
                System.out.println("done");
                response.sendRedirect("index.jsp");

            } catch (Exception e) {
                e.printStackTrace();
            }
        %>
    </body>
</html>

这里当我用数据库名称验证用户名时,更新不会触发,而是完整的更新语句不起作用我添加了错误的屏幕截图我正在获取

0 个答案:

没有答案