Possible Duplicate:
Java user class
看看我的代码。哪里不对?输出是“找不到用户”。
package it.unitn.ing.guide;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
public class LoginDao {
private static Statement stm = null;
private static ResultSet rs = null;
private static Connection con = null;
private static int i;
private it.unitn.ing.guide.User user;
private User user_set;
public User authenctication(String eMail, String password, int i) {
try {
ArrayList user_set = new ArrayList();
con = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "root");
stm = con.createStatement();
rs = stm.executeQuery("SELECT * FROM User,Role WHERE (user.id=role.id) AND (user.email='" + eMail + "')");
while (rs.next()) {
while (rs.next()) {
User user = new User();
user.setAddress(rs.getString(""));
user.setCountry(rs.getString(""));
user.setCreatedBy(rs.getString(""));
user.setEMail(rs.getString(""));
user.setId(rs.getInt(""));
user.setIsLocked(rs.getString(""));
user.setLastLoginDate(rs.getDate(""));
user.setName(rs.getString(""));
user.setPassword(rs.getString(""));
user.setPasswordFormat(rs.getString(""));
user.setPasswordFormat(rs.getString(""));
user.setPasswordSalt(rs.getString(""));
user.setPhoneNumber(rs.getInt(""));
user.setPhoneNumberNull(rs.getBoolean(""));
user.setRegistrationDate(rs.getDate(""));
user.setRoleId(rs.getInt(""));
user.setUserName(rs.getString(""));
user_set.add(user);
}
}
} catch (Exception sqlEx) {
System.out.println("sqlexecuteException: " + sqlEx.toString());
}
return user_set;
}
public static void main(String[] args) throws Exception {
LoginDao loginDao = new LoginDao();
User user = loginDao.authenctication("rashed", "rashed", i);
if (user != null) {
System.out.println(user.getId());
} else {
System.out.println("No user Found");
}
}
}