mySQL的SELECT不显示JSP的输入,仅显示mySQL的输入

时间:2019-07-05 09:20:10

标签: mysql jsp

我需要帮助。我还是JSP和MySQL的新手。我知道我不应该使用scriptlet,但这不是我要问的问题,这是问题所在。选择查询仅返回来自mySQL的输入,而不返回来自JSP的输入。由于我是jsp和数据库的新手,并且错误似乎很奇怪,因此我不知道如何解决该问题。

当我运行register.jsp时,我使用以下输入。 “ aaa”代表用户名,bbb代表密码,ccc代表电子邮件(都是字符串)

mySQL确实显示了该记录

name     password       email
aaa      bbb            ccc

不过,当我在mySQL编辑器中执行时:

select * from person where name='aaa';

它返回null / null / null

如果我键入

INSERT INTO person VALUES ( 'ppp', 'ooo', 'qqq' )

mySQL现在显示该记录

name     password       email
aaa      bbb            ccc
ppp      ooo            qqq

当我在mySQL编辑器中执行时:

select * from person where name='ppp';

它返回ppp / ooo / qqq

select * from person where name='aaa';

它返回null / null / null

register.jsp

<form>
    username:  <input type="text" name="username"> <br>
    password: <input type="text" name="password1"> <br>
    <!-- retyped password: <input type="text" name="password2"> <br> -->
    email:      <input type="text" name="email"> <br>
    <!-- name:  <input type="text" name="name"> <br> -->
    <input type="submit" name="submit" value="register">  
     <a href="login.jsp"> login</a> <br>
     </form>

     <%@ page import="java.sql.*" %>
     <%@ page import="javax.sql.*" %>
     <%
        String email =  request.getParameter("email");
        String username =  request.getParameter("username");
        session.setAttribute("email", email);
        String password = request.getParameter("password1");
        Class.forName("com.mysql.jdbc.Driver");
        java.sql.Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/myDB?verifyServerCertificate=false&useSSL=true" , "root", "cs160project");
        Statement statement = connection.createStatement();
        if ( email != null && username != null && password != null ) {
            String temp1 = " ' " + username + " ' ";
            String temp2 = " ' " + password  + " ' ";
            String temp3 = " ' " + email + " ' ";
            int temp = statement.executeUpdate("INSERT INTO person values(" + temp1 + "," + temp2 + "," + temp3 + ");" ); 
        out.println("registered successfully");
        }
     %>

0 个答案:

没有答案