【发布时间】:2015-12-05 07:01:02
【问题描述】:
我正在尝试在 jsp netbeans 中设置登录时间和注销时间 Web 应用程序。当我尝试将注销时间保存到 mysql 数据库中时,日期和时间正确保存,但用户名和密码都保存为空。请帮我将用户名和密码正确保存到表中。 这是我的注销代码:
`<%@ page import ="java.sql.*" %>
`<%String url="jdbc:mysql://localhost:3306/mysql";`
` String user="root";`
` String password="";`
`Class.forName("com.mysql.jdbc.Driver");`
`Connection con = DriverManager.getConnection(url, user, password);`
`Statement st = con.createStatement();`
`String uname1= request.getParameter("first_name");`
`String pwd = request.getParameter("pass");`
`session.setAttribute("fname", uname1);`
`session.setAttribute("pass", pwd);`
`int i = st.executeUpdate("insert into logut values ('" + uname1 + "','" + pwd + "',now())");`
`if (i > 0) `
`{out.write("<script type='text/javascript'>\n");`
`out.write("alert(' Logout Successfully!!! ');\n");`
`out.write("setTimeout(function({window.location.href='index.jsp'},1000);");`
`out.write("</script>\n");`
`}`
%>`
我的数据库保存如下: id= null pass=null 并且日期和时间正确保存。帮帮我。谢谢你提前。
【问题讨论】:
-
uname1中没有数据? -
了解准备好的声明。
-
首先检查
uname1是否有任何数据,是的,您的id必须是AI才能自动插入。 -
尝试使用 sysout 显示
uname1和pwd值,以验证它们的值是否不同于 null -
为了连接池和 sql-injection,改变你连接和执行 DML 的方式。你确定你最后没有任何触发器?也许后端 sql 拒绝插入或事务性问题。