SQL中有条语句叫 update 
等你把这个弄懂了再来问吧

解决方案 »

  1.   

    if 你是原密码正确
     update table set 密码=新密码 where 用户名=你
    这个够形象了吧,哈哈
      

  2.   

    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <%@ include file="main.jsp"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>修改密码</title>
    <link href="images/basic.css" rel="stylesheet" type="text/css" />
    <script language="javascript">
    function check()
    {
       var oldpwd=document.form1.oldpwd.value;
       var newpwd=document.form1.newpwd.value;
       var confpwd=document.form1.confpwd.value;
       if(oldpwd=="")
       {
      alert("请您输入旧密码!");
      document.form1.oldpwd.focus();
      return false;
       }
       if(newpwd=="")
       {
      alert("请您输入新密码!");
      document.form1.newpwd.focus();
      return false;
       }
       if(confpwd=="")
       {
      alert("请您确认新密码!");
      document.form1.confpwd.focus();
      return false;
       }
       if(newpwd!=confpwd)
       {
          alert("新密码与确认密码输入不一致,请您重新输入!");
      document.form1.newpwd.value="";
      document.form1.confpwd.value="";
      document.form1.newpwd.focus();
      return false;
        }
       return true;
    }
    </script>
    </head><body>
    <%
       String sql="";
       ResultSet rs=null;
    %>
    <%
       String act=Str_rep(request.getParameter("act"));
       if(act.equals("ok"))
       {
      String uname=Str_rep(request.getParameter("uname"));
      String oldpwd=Str_rep(request.getParameter("oldpwd"));
      String newpwd=Str_rep(request.getParameter("newpwd"));
      
      sql="select * from users where id="+u_id+" and uname='"+uname+"' and pwd='"+oldpwd+"'";
      //out.print(sql+"<br>");
      rs=slink.executeQuery(sql);
      if(rs.next())
      {
          sql="update users set pwd='"+newpwd+"' where id="+u_id+" and uname='"+uname+"'";
      //out.print(sql+"<br>");
      slink.executeUpdate(sql);
      session.setAttribute("pwd",newpwd);
      out.print("<script>alert('提示:密码修改成功!');</script>");
       }
      else
      {
      out.print("<script>alert('警告:旧密码输入错误!');</script>");
       }
      rs.close();
        }
    %>
      <table width="560" border="0" align="center" cellpadding="2" cellspacing="1" class="table_southidc">
    <form id="form1" name="form1" method="post" action="?act=ok" onsubmit="return check();">
      <tr>
        <td width="180" height="25" align="right" class="td_bgcolor1">用户名:</td>
        <td width="369" height="25" class="td_bgcolor1">
          <input name="uname" type="text" id="uname" value="<%=u_uname%>" readonly="yes" />    </td>
      </tr>
      <tr>
        <td height="25" align="right" class="td_bgcolor1">旧密码:</td>
        <td height="25" class="td_bgcolor1"><input name="oldpwd" type="password" id="oldpwd" />
          <span class="xing">*</span></td>
      </tr>
      <tr>
        <td height="25" align="right" class="td_bgcolor1">新密码:</td>
        <td height="25" class="td_bgcolor1"><input name="newpwd" type="password" id="newpwd" />
          <span class="xing">*</span></td>
      </tr>
      <tr>
        <td height="25" align="right" class="td_bgcolor1">确认新密码:</td>
        <td height="25" class="td_bgcolor1"><input name="confpwd" type="password" id="confpwd" />
          <span class="xing">*</span></td>
      </tr>
      <tr>
        <td height="25" align="right" class="td_bgcolor2">&nbsp;</td>
        <td height="25" class="td_bgcolor2"><input type="submit" name="Submit" value="修改" />
          <input type="reset" name="Submit2" value="重置" /></td>
      </tr>
    </form>
    </table>
    <%
          slink.closeDB();
    %>
    </body>
    </html>
    参考下就知道了