日期:2014-05-17  浏览次数:20678 次

用来更改密码的程序,但是就算帐号密码都提供正确了也改不了
package dao;
import java.sql.*;
public class Gai{

public String gai(String username,String yuanpassword,String password)
{
Connection conn=null;
Statement stmt=null;
String sql;  
ResultSet rs=null;
DB db=new DB();
conn=db.getConn();
try{
stmt=conn.createStatement();
sql="select * from yonghu where username='"+username+"'";
  rs=stmt.executeQuery(sql);
  while(rs.next()) //如果查到了该用户,则再把相应的密码取出来
  {  
  String temp=rs.getString("password");
  if(yuanpassword.equals(temp))
  {String sql2="update yonghu set password='"+password+"' where username='"+username+"'";
  stmt.executeUpdate(sql2);
  return "success"; //只有用户名和密码都正确时才会返success
  }
  else 
  return "wrong";
  }
  }
catch(SQLException e2)
  {
  System.out.println("数据库存在异常!查操作时出现错误");
  System.out.println(e2.toString());
  }
finally
  {
  try
  {
  if(rs != null) rs.close();
  if(stmt != null) stmt.close();
  if(conn!= null) conn.close();
  }
  catch(SQLException e)
  {
  System.out.println("数据库存在异常!查操作时出现错误");
  }  
  }
return "wrong";
}
}
返回servlet的时候总是返回wrong,我打开数据库输入个正确的帐号和密码还是返回wrong,所以我判断是我返回success的那部分有错误导致没有被执行 但是看了许久无果 求大神点睛=。=

------解决方案--------------------
String temp=rs.getString("password");
System.out.println(temp);
if(yuanpassword.equals(temp))
能得到这个对象么?你先看一下