日期:2014-05-17 浏览次数:20777 次
public class LoginDaoIm implements LoginDao { private SessionFactory sessionFactory; public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public boolean canLogin(String username, String password) { Session session = sessionFactory.openSession(); // Transaction tran = session.beginTransaction(); String hql = "from Login i where i.username=? and i.password =?"; //// String hql ="from Login "; [color=#FF6600]Query query = session.createQuery(hql);[/color] query.setString(0,username); query.setString(1, password); // List list = query.list(); // Iterator iterator = list.iterator(); // while(iterator.hasNext()){ // Login login= (Login) iterator.next(); // System.out.println(login.getPassword()+login.getUsername()); // } // tran.commit(); List list = query.list(); session.close(); if(list.size()>0){ return true; } return false; }