首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

页面修改数据后记录没有变化是咋回事

2012-09-24 
页面修改数据后记录没有变化是怎么回事xg.jsp% request.setCharacterEncoding(gb2312) String number

页面修改数据后记录没有变化是怎么回事
xg.jsp 
 <%
request.setCharacterEncoding("gb2312");
String number=request.getParameter("id");
  Connection conn=(Connection)DatabaseConn.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from renyuan where id= "+number);  
  rs.next();
  %>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; 人员编号
  <label>
  <input type="text" name="textfield" value="<%=rs.getString("ry_id")%>">
  </label>
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; 人员姓名
  <input type="text" name="textfield2" value="<%=rs.getString("ry_name")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 性&nbsp; 别 
  <input type="text" name="textfield3" value="<%=rs.getString("ry_sex")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 国&nbsp; 籍 
  <input type="text" name="textfield4" value="<%=rs.getString("country")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 民&nbsp; 族 
  <input type="text" name="textfield5" value="<%=rs.getString("nation")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; 出生年月
  <input type="text" name="textfield6" value="<%=rs.getString("birthday")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; 电话号码
  <input type="text" name="textfield7" value="<%=rs.getString("telephone")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 年&nbsp; 龄 
  <input type="text" name="textfield8" value="<%=rs.getString("age")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; 工作时间
  <input type="text" name="textfield9" value="<%=rs.getString("worktime")%>">
  </p>
  <p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 等&nbsp; 级 
  <input type="text" name="textfield10" value="<%=rs.getString("ry_mj")%>">
  </p>
  <p> <br>
  </p>
  <form name="form1" method="post" action="xg1.jsp">
  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  <label>
  <input type="submit" name="Submit" value="提交">
  </label>
  </form>
  <p> <br>
  </p>

xg1.jsp 
<%  
try{
  request.setCharacterEncoding("gb2312");
  String number=request.getParameter("id");
  Connection conn=(Connection)DatabaseConn.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from renyuan"); 


  String ry_id=request.getParameter("ry_id");
  String ry_name=request.getParameter("ry_name");
  String ry_sex=request.getParameter("ry_sex");
  String country=request.getParameter("country");
  String nation=request.getParameter("nation");
  String birthday=request.getParameter("birthday");
  String telephone=request.getParameter("telephone");
  String age=request.getParameter("age");
  String worktime=request.getParameter("worktime");
  String ry_mj=request.getParameter("ry_mj");  
   
  String sql="update renyuan set ry_id='"+ry_id+"' ,ry_name='"+ry_name+"',ry_sex='"+ry_sex+"',country='"+country+"',nation='"+nation+"',birthday='"+birthday+"',telephone="+telephone+",age="+age+",worktime='"+worktime+"',ry_mj='"+ry_mj+"'where id= "+number;
  stmt.executeUpdate(sql);
  response.sendRedirect("index4.jsp");
  }
  catch(Exception e){
  e.printStackTrace();
  }
%>

delete.jsp

 <%

Connection conn=(Connection)DatabaseConn.getConnection();
Statement stmt=conn.createStatement(); 
  String number=request.getParameter("id");
  String sql="delete from renyuan where ry_id= "+number;
  stmt.execute(sql);
  response.sendRedirect("index4.jsp");
   
  %>

DatabaseConn.java
package javabean;

import java.sql.SQLException;
import javax.naming.*;
import javax.sql.DataSource;
import java.sql.Connection;



public class DatabaseConn {
public static synchronized Connection getConnection() throws SQLException, NamingException {
try{
Context InitialContext=new javax.naming.InitialContext();
Context envCtx=(Context)InitialContext.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/system");
return (Connection) ds.getConnection();
}
catch(SQLException e){
throw e;
}
catch(NamingException e){
throw e;
}
}
}
修改页面的数据修改后没有变化,删除页面的数据删除不了,请大侠帮忙看哈,不胜感激 


[解决办法]
楼主啊,
<form name="form1" method="post" action="xg1.jsp">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<label>
<input type="submit" name="Submit" value="提交">
你都没有提交任何数据到xg1.jsp,怎么会更新到数据?你在xg1.jsp里获取的所有数据都是null

你要将
<input type="text" name="textfield" value="<%=rs.getString("ry_id")%>">
这些语句全部放到form里去
同时更改name的名称,如
<input type="text" name="ry_id" value="<%=rs.getString("ry_id")%>">
[解决办法]
xg.jsp 你的form的位置放错了吧 ,什么都没有提交什么呀???
还有修改页面的数据修改后没有变化,肯定是修改错了呀 把报错的代码贴出来就行了!
[解决办法]
需要改成如下方式:
<form name="form1" method="post" action="xg1.jsp">
<p>&nbsp;&nbsp;&nbsp;&nbsp; 人员编号
<label>
<input type="text" name="ry_id" value="<%=rs.getString("ry_id")%>">
</label>
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 人员姓名


<input type="text" name="ry_name" value="<%=rs.getString("ry_name")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 性&nbsp; 别
<input type="text" name="ry_sex" value="<%=rs.getString("ry_sex")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 国&nbsp; 籍
<input type="text" name="country" value="<%=rs.getString("country")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 民&nbsp; 族
<input type="text" name="nation" value="<%=rs.getString("nation")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 出生年月
<input type="text" name="birthday" value="<%=rs.getString("birthday")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 电话号码
<input type="text" name="telephone" value="<%=rs.getString("telephone")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 年&nbsp; 龄
<input type="text" name="age" value="<%=rs.getString("age")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 工作时间
<input type="text" name="worktime" value="<%=rs.getString("worktime")%>">
</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 等&nbsp; 级
<input type="text" name="ry_mj" value="<%=rs.getString("ry_mj")%>">
</p>
<p> <br>
</p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>

热点排行