修改页面需要修改的信息显示成功,但更改后并没有更新到数据库!!
修改页面的JSP代码如下
  <%
    String kcbh=request.getParameter("kcbh");
    ResultSet rs2=cxjg.get_cxjg2(kcbh);
    if(rs2.next())
    {
  %>
  <body>
  <form id="form1" method="post" action="/JWXK/servlet/EDITKC">
    <table id=table1>
      <tr>
        <td>&nbsp; 
          <font size=2>课程编号:</font>
          <input id="t1" name="t1" type="text" width=120 value="<%out.print(rs2.getString(1));%>">
        </td>
        <td>
          <font size=2>课程名称:</font>
          <input id="t2" name="t2" type="text" width=120 value="<%out.print(rs2.getString(2));%>">
        </td>
      </tr>
      <tr>
        <td>
          <font size=2>学时:</font>
          <input id="t3" name="t3" type="text" width=120 value="<%out.print(rs2.getString(3));%>">
        </td>
        <td>
          <font size=2>任课教师:</font>
          <input id="t4" name="t4" type="text" width=120 value="<%out.print(rs2.getString(4));%>">
        </td>
      </tr>
      <tr>
        <td>
          <font size=2>上课时间:</font>
          <input id="t5" name="t5" type="text" width=120 value="<%out.print(rs2.getString(7));%>">
        </td>
        <td>
          <font size=2>上课地点:</font>
          <input id="t6" name="t6" type="text" width=120 value="<%out.print(rs2.getString(8));%>">
        </td>
      </tr>
      <tr>
        <td>
          <font size=2>限报人数:</font>
          <input id="t7" name="t7" type="text" width=120 value="<%out.print(rs2.getString(5));%>">
        </td>
        <td>
          <font size=2>限报院系:</font>
          <input id="t9" name="t9" type="text" width=120 value="<%out.print(rs2.getString(11));%>">
        </td>
      </tr>
      <tr>
        <td>
          <font size=2>限报专业:</font>
          <input id="t8" name="t8" type="text" width=120 value="<%out.print(rs2.getString(10));%>">
        </td>
        <td>
          <font size="2">限报性别:</font>
          <select name="s1" id="s1" width="120">
          <option value="<%out.print(rs2.getString(9));%>"><%out.print(rs2.getString(9));%></option>
          <option value="无">无</option>
          <option value="男">男</option>
          <option value="女">女</option>
          </select>
        </td>
      </tr>
      <tr>
        <td cospan=2>
          <input type="submit" value="提交">&nbsp;&nbsp;
          <input type="button" value="关闭" onclick="window.close()">
        </td>
      </tr>
    
    </table>
    </form>
  </body>
  <%
    }
  %>
修改数据的JAVA代码如下:
Connection conn=null;
//Statement stmt=null;try
{   
conn=DBConnection.getConnection();
request.setCharacterEncoding("gb2312");
String t1=request.getParameter("t1");
String t2=request.getParameter("t2");
String t3=request.getParameter("t3");
String t4=request.getParameter("t4");
String t5=request.getParameter("t5");
String t6=request.getParameter("t6");
String t7=request.getParameter("t7");
String t8=request.getParameter("t8");
String t9=request.getParameter("t9");
String s1=request.getParameter("s1");


conn=DBConnection.getConnection_access();
   
    Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
   
    
    String sql="update 课程表  set 课程名称='"+t2+"',学时='"+t3+"',任课教师='"+t4+"',限报人数='"+t5+"',上课时间='"+t6+"',上课地点='"+t7+"',限报性别='"+s1+"',限报专业'"+t8+"',限报院系='"+t9+"' where 课程编号='"+t1+"'";
    
  stmt.executeUpdate(sql);
  
    
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
System.out.print("<script>window.close();</script>");
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} public void init() throws ServletException {
}}

解决方案 »

  1.   

    Statement  断点调试下 看看是不是成功连接了
    其他的没看出来
    帮你顶下
      

  2.   

    谢谢,在MyEclipse里面设置的断点,但不知道是我断点设置不成功怎样看不到变量里面的内容==!
      

  3.   

    servlet端接受值的地方是怎么写的.
    是接受t1,t2,t3.....吗?
      

  4.   

    哦, 不好意思, 没看下面java代码.
    你把sql打印后台看一下update语句, 是否正确
      

  5.   

    或者把
    System.out.print("<script>window.close();</script>"); 改成
    System.out.print("sql"); 把显示出来的sql语句直接在数据库运行看看, 是否正常.
      

  6.   

    晕.. 我看着看着有点奇怪.
    System.out.print("<script>window.close();</script>");  这个部分你确定执行完修改操作之后页面会被关闭掉吗?
      

  7.   

    另外.. 你这字段是带中文的. 你的java文件是gb2312格式的吗?
      

  8.   

    确实没有,添加页码的JAVA代码里面<script>window.opener.location.reload();window.close();</script>也没有进行父页的刷新
      

  9.   


    没有显示我用的是ACCESS数据库
      

  10.   

    问题解决了么?
    你最好把SQL语句打印出来.
    看看SQL对不对. 如果SQL没问题确保stmt.executeUpdate(sql);语句要执行成功. 在catch哪一块多写一些输出的代码看看..
    还有system.out.println是输出到控制台的.
    这样他只会把javascript脚本输出到控制台, 浏览器是没什么任何反应的.
    你要输出到浏览器需要用writer.
    PrintWriter out = response.getWriter();
    out.println("你的js内容") 才可以.
      

  11.   

    解决了,输出SQL语句发现有个字段的格式不对,已经改好了,谢谢啦