紧急!请大神帮帮忙!

我在努力ing 2014-03-25 09:55:35
我在插入数据时提示
严重: Servlet.service() for servlet default threw exception
com.microsoft.sqlserver.jdbc.SQLServerException: 不能将值 NULL 插入列 'username',表 'seconddhand.dbo.usertable';列不允许有空值。INSERT 失败。
'username'是vchar类型的,而且也有值,不知道为什么老是提示为null。
...全文
87 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
我在努力ing 2014-03-25
  • 打赏
  • 举报
回复
又长知识了!
jxplus 2014-03-25
  • 打赏
  • 举报
回复
结贴吧,哥们。
jxplus 2014-03-25
  • 打赏
  • 举报
回复
报错,应该是username这个字段你在数据库又不是设成自增序列,所以是null。
我在努力ing 2014-03-25
  • 打赏
  • 举报
回复
真的可以了,谢谢你的解答!请问怎么给分你呢?我是论坛新手。
jxplus 2014-03-25
  • 打赏
  • 举报
回复
你的username是主键,然后你配置了:<generator class="native" />,这个是表明用各自数据对应的自增序列获取主键,当然不会取你从页面传过来的参数,把配置改成:<generator class="assigned" />,就可以了。
我在努力ing 2014-03-25
  • 打赏
  • 举报
回复
usertable的hibernate配置hbm文件是自己生成的 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="org.model.Usertable" table="usertable" schema="dbo" catalog="seconddhand"> <id name="username" type="java.lang.String"> <column name="username" length="20" /> <generator class="native" /> </id> <property name="password" type="java.lang.String"> <column name="password" length="15" not-null="true" /> </property> </class> </hibernate-mapping>
jxplus 2014-03-25
  • 打赏
  • 举报
回复
usertable的hibernate配置hbm文件贴出来看看。
我在努力ing 2014-03-25
  • 打赏
  • 举报
回复
sql是hibernate自己连接的吧
我在努力ing 2014-03-25
  • 打赏
  • 举报
回复
这是.dao的代码 package org.dao; import org.model.Usertable; public interface RegisterDao { public void saveUsertable(Usertable usertable); } 这是.dao.imp的代码 package org.dao.imp; import java.util.List; import org.dao.RegisterDao; import org.model.Usertable; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; public class RegisterDaoImp extends HibernateDaoSupport implements RegisterDao{ public void saveUsertable(Usertable usertable){ getHibernateTemplate().save(usertable); } } 这是.service的代码 package org.service; import org.model.Usertable; public interface RegisterService { public void saveUsertable(Usertable usertable); } 这是.service.imp的代码 package org.service.imp; import org.dao.RegisterDao; import org.model.Usertable; import org.service.RegisterService; public class RegisterServiceManage implements RegisterService{ private RegisterDao registerDao; public void setRegisterDao(RegisterDao registerDao){ this.registerDao=registerDao; } public void saveUsertable(Usertable usertable){ this.registerDao.saveUsertable(usertable); } } 这是action的代码 package org.action; import java.util.Map; import org.model.Usertable; import org.service.RegisterService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport{ protected RegisterService registerService; protected Usertable usertable; public Usertable getUsertable(){ return this.usertable; } public void setUsertable(Usertable usertable){ this.usertable=usertable; } public void setRegisterService(RegisterService registerService){ this.registerService=registerService; } public String execute() throws Exception{ System.out.print(usertable.getUsername()); Usertable ut=new Usertable(); ut.setUsername(usertable.getUsername()); ut.setPassword(usertable.getPassword()); registerService.saveUsertable(ut); return SUCCESS; } } 这是jsp页面的代码 <body> <div align="center"> <s:form action="register.action" method="post"> 用户注册 <br/> <s:textfield name="usertable.username" label="用户名" size="20"/> <s:password name="usertable.password" label="密码" size="21"/> <s:submit value="注册"></s:submit> </s:form> </div> </body>
jxplus 2014-03-25
  • 打赏
  • 举报
回复
sql打印出来看看。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧