日期:2014-05-20  浏览次数:20852 次

关于jsp修改Oracle数据库中记录的问题
代码大致如下:
public boolean update(Provider p){
boolean isUpdate=false;
openConection();
String sql="update provider set p_id=?,providername=?,description=?,contacts=?,telephone=?,fax=?,address=?";
try {
ps=con.prepareStatement(sql);
ps.setInt(1,p.getPid());
ps.setString(2,p.getProvidername());
ps.setString(3,p.getDescription());
ps.setString(4,p.getContacts());
ps.setString(5,p.getTelephone());
ps.setString(6,p.getFax());
ps.setString(7,p.getAddress());
int count=ps.executeUpdate();
isUpdate=count>0?true:false;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
shutdown();
}
return isUpdate;
}

<%
  Provider p2=new Provider();
  String msg=request.getParameter("msg");
  if("update".equals(msg)){
  String name2=request.getParameter("proName");
  p2.setProvidername(name2);
  String desc2=request.getParameter("proDesc");
  p2.setDescription(desc2);
  String contact2=request.getParameter("contact");
  p2.setContacts(contact2);
  String phone2=request.getParameter("phone");
  p2.setTelephone(phone2);
  String fax2=request.getParameter("fax");
  p2.setFax(fax2);
  String address2=request.getParameter("address");
  p2.setAddress(address2);
  boolean isUpdate=digger.update(p2);
  if(isUpdate){
  out.println("<script type=\"text/javascript\">");
  out.print("alert(\"添加成功\")");
  out.println("</script>");
  }else if(!isUpdate){
  out.println("<script type=\"text/javascript\">");
  out.print("alert(\"添加失败\")");}
  out.println("</script>");
  }
   
  %>
<input name="button" id="button" value="修改" class="input-button" type="submit" onclick="location.href='providermodify.jsp?msg=update'">
执行后数据库中内容被清空!!!!!
求解!!!

------解决方案--------------------
1.update语句少了where条件
2.public boolean update(Provider p),这个形参的实参在那里?。没实参当然都update成空了