<form class="form-horizontal" action="${path}/news/add.do" method="post" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="inputnewstopic">主题</label>
<div class="controls">
<input type="text" class="input-xlarge" id="inputnewstopic" name="inputnewstopic" maxlength="80" required placeholder="主题内容">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputinput">发布用户</label>
<div class="controls">
<select name="inputinput" class="span5" required>
<option>销售人员</option>
<option>维修人员</option>
<option>经理/管理员</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputnewscontent">内容</label>
<div class="controls">
<textarea rows="8" cols="50" class="input-xlarge" id="inputnewscontent" name="inputnewscontent" required placeholder="请输入要发布的公告内容"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputnewsdate">订购日期</label>
<div class="controls">
<input type="date" name="inputnewsdate" id="inputnewsdate" required>
</div>
</div>
public interface INewsDao {
public void create(NewsValue nv)throws Exception;
//增加公告记录
public void delete(NewsValue nv)throws Exception;
//删除公告记录
public List<NewsValue> getList() throws Exception;
//返回所有公告记录
public List<NewsValue> search(String newstopic) throws Exception;
//根据主题返回搜索公告记录
public NewsValue get(int newsid) throws Exception;
}
public void create(NewsValue nv) throws Exception {
// 增加新的销售记录
String sql="INSERT INTO `carsell`.`news`(`newsid`,`newstopic`,`newscontent`,`newsinput`,`newsdate`) VALUES ( NULL,?,?,?,?)";
Connection cn=null;
try{
cn=ConnectionFactory.getConnection();
PreparedStatement ps =cn.prepareStatement(sql);
ps.setString(1, nv.getNewstopic());
ps.setString(2,nv.getNewscontent());
ps.setString(3, nv.getNewsinput());
ps.setString(4, nv.getNewsdate());
ps.executeUpdate();
ps.close();
}catch(Exception e){
throw new Exception("公告记录DAO增加错误:"+e.getMessage());
}finally{
cn.close();
}
}
public interface INews {
public void add(int newsid,String newstopic,String newscontent,String newsinput,String newsdate) throws Exception;
public void delete(int newsid) throws Exception;
public NewsValue getNews(int newsid) throws Exception;
public List<NewsValue> getlist() throws Exception;
public List<NewsValue> search(String newstopic) throws Exception;
public void add(int newsid, String newstopic, String newscontent, String newsinput, String newsdate)
throws Exception {
//增加公告
NewsValue nv=new NewsValue();
nv.setNewsid(newsid);
nv.setNewstopic(newstopic);
nv.setNewscontent(newscontent);
nv.setNewsinput(newsinput);
nv.setNewsdate(newsdate);
INewsDao ndo=DaoFactory.getNewsDao();
ndo.create(nv);
}
try {
request.setCharacterEncoding("utf-8");
INews news=BusinessFactory.getNews();
int newsid=0;
String newstopic=request.getParameter("inputnewstopic");
String newscontent=request.getParameter("inputnewscontent");
String input=request.getParameter("inputinput");
String newsdate=request.getParameter("inputnewsdate");
news.add(newsid,newstopic,newscontent,input,newsdate);
response.setCharacterEncoding("utf-8");
response.sendRedirect("main.do");
//转发到员工主页
} catch (Exception e) {
String mess=e.getMessage();
response.sendRedirect("../index/error.jsp?mess="+mess);
e.printStackTrace();
}
}
java.lang.Exception: 公告记录DAO增加错误:Column 'newscontent' cannot be null
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- threenewbee 2019-06-02 16:27关注
ps.setString(2,nv.getNewscontent());
调试下这里有没有取到值
如果没有,页面form是否完整,用抓包工具看下post的请求解决 无用评论 打赏 举报
悬赏问题
- ¥15 matlab图像高斯低通滤波
- ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
- ¥15 钢筋实图交点识别,机器视觉代码
- ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
- ¥50 400g qsfp 光模块iphy方案
- ¥15 两块ADC0804用proteus仿真时,出现异常
- ¥15 关于风控系统,如何去选择
- ¥15 这款软件是什么?需要能满足我的需求
- ¥15 SpringSecurityOauth2登陆前后request不一致
- ¥15 禅道二次开发编辑版本,上传不了发行包