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

哥哥教教小弟我

2012-03-23 
哥哥教教我importjava.io.*importjava.net.*importshuj.*importjava.sql.*importjavax.sql.*importja

哥哥教教我
import   java.io.*;
import   java.net.*;
import   shuj.*;
import   java.sql.*;
import   javax.sql.*;
import   javax.servlet.*;
import   javax.servlet.http.*;


public   class   passwd_xg   extends   HttpServlet   {
       
       
        protected   void   processRequest(HttpServletRequest   request,   HttpServletResponse   response)
        throws   ServletException,   IOException   {
                response.setContentType( "text/html;charset=UTF-8 ");
                PrintWriter   out   =   response.getWriter();
                try{
                        String   password   =   request.getParameter( "textfield ");
                          String   username       =   request.getParameter( "textfield2 ");
                            String   name   =   request.getParameter( "name8 ");
                          DBConnection   dbc   =   new   DBConnection();
                          String   sqlpw   =   "update   adminzw   set   密码= ' "+username+ " '   where   密码   =   ' "+password   + " ' ";
                          dbc.executeQuery(sqlpw);
                          String   sql   =   "selest   *   from   adminzw     账号= ' "+name+ " ' ";
                          out.println( " <h2>   恭喜你资料修改成功!!   </h2>   <br> ");  
                        /*   ResultSet   rs   =   dbc.executeQuery(sql);
                          if(rs.next()){
                                  response.sendRedirect( "admin_index.jsp ");
                          }*/
                       
                }
                catch(Exception   e)
                {
                        out.println( " <h2>   捕获到异常!!   </h2>   <br> ");
                        out.print( " <html> ")   ;    
                        out.println( " <body   bgcolor=   #CC66FF> ");


                        out.println( " </body> ");
                          out.print( " </html> ")   ;    
                }
                             
               
        }
       
     
        protected   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)
        throws   ServletException,   IOException   {
                processRequest(request,   response);
        }
       
     
        protected   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)
        throws   ServletException,   IOException   {
                processRequest(request,   response);
        }
       
   
}
这段代码出什么问题了呢?
用户的密码修改不了

[解决办法]
dbc.executeQuery(sqlpw);应该是dbc.executeUpdate(sqlpw);

[解决办法]
抛出异常错错!
[解决办法]
dbc.executeUpdate(sqlpw)
[解决办法]
楼上的对,你修改的UPDATE错误了
[解决办法]
String sqlpw = "update adminzw set 密码= ' "+username+ " ' where 密码 = ' "+password + " ' ";
这里的错误吧

[解决办法]
update adminzw set 密码= ' " + newpassword + " ' where 帐号= ' " + username + " ' and 密码= ' " + password + " '
[解决办法]
String sqlpw = "update adminzw set 密码= ' "+username+ " ' where 密码 = ' "+password + " ' ";
dbc.executeQuery(sqlpw);


1) 改密码要有2个条件 不能是把所有密码为8888的都改了 需要看帐号
2)执行update语句用 executeUpdate

[解决办法]
首先你写的sql语句就有逻辑上的错误,改成
update adminzw set 密码= ' " + newpassword + " ' where 帐号= ' " + username + " ' "
其次用
dbc.executeUpdate来执行sql语句,你用的是查询功能,是要返回记录集的。
[解决办法]
String sqlpw = "update adminzw set 密码= ' "+username+ " ' where 密码 = ' "+password + " ' "; 更新的where条件不能和set中的字段相同,这个是数据库更新原理。
dbc.executeQuery(sqlpw); 这里不能使用executeQuery,这个是做检索时用的返回的是result,应该使用execteupdate,他返回的是一个整形数,根据这个数可以判断是否操作成功
[解决办法]
String sqlpw = "update adminzw set 密码= ' "+username+ " ' where 密码 = ' "+password + " ' ";


dbc.executeQuery(sqlpw);


1) 改密码要有2个条件 不能是把所有密码为8888的都改了 需要看帐号
2)执行update语句用 executeUpdate

热点排行