1.mysql的数据表是
建立的数据表为user.sql
create database user;
use user;
create table login
(
id int primary key auto_increment,
name varchar(25),
password varchar(25),
email varchar(25)
);
insert into login(id,name,password,email) values (null, "kobe", "1812", "qdq@163.com");
2.jsp登录页面的程序是:
<%
request.setCharacterEncoding("gb2312");
String name=request.getParameter("name");
String password=request.getParameter("password");
String email=request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/user?user=root&password=root";
Connection conn = DriverManager.getConnection(url);
String sql = "insert into login values( null,?, ?, ?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1,name);
pstmt.setString(2, password);
pstmt.setString(3, email);
pstmt.executeUpdate();
pstmt.close();
conn.close();
%>
<body>
<form action="Writewords.jsp" method="post" name="form1">
姓名:
<input name="name" type="text" size="20" maxlength="25">
密码:
<input name="password" type="text" size="20" maxlength="25">
Email:
<input name="email" type="text" size="30" maxlength="32">
<input type="submit" name="Submit" value="提交">
</form>
</body>
3.数据表中的结果要么是:
id name password email
1 kobe 1812 qdq@163.com 或者是:
id name password email
1 kobe 1812 qdq@163.com
2 null null null
3 null null null
------解决方案--------------------------------------------------------
回帖是一种美德!每天回帖即可获得 10 分可用分!
------解决方案--------------------------------------------------------
你在insert into 之后,是否提交事务呢(commit)
------解决方案--------------------------------------------------------
且而你的主键怎么能为空啊?
------解决方案--------------------------------------------------------
插入信息的页面也是当前页面吧,你没有判断name,password,email是否为空。在页面第一次加载还没有输入数据的时候就执行了数据库的插入操作,这时request.get……取不到对应的数据,所以值为null,入库就是null了。有时候没有数据应该就是事务没有提交的原因。
------解决方案--------------------------------------------------------
事务默认就是自动提交的,不要手动设置了。建议你插入数据前先把他们打印出来看一下
------解决方案--------------------------------------------------------