public boolean findByNameAndPassword(Person person) {
boolean result = true;
Transaction tx = null;
SessionFactory sf = this.sessionFactory;
Session session = sf.getCurrentSession();
try{
tx = session.getTransaction();
tx.begin();
Query q = session
.createQuery("select person(id) from person where username=:username and password=:password");
q.setString("username",person.getUsername());
q.setString("password", person.getPassword());
if (q.list().isEmpty())
result = false;
}
tx.commit();
} catch (Exception e) {
e.printStackTrace();
if (tx != null && tx.isActive()) {
try {
// Second try catch as the rollback could fail as well
tx.rollback();
} catch (HibernateException e1) {
e1.printStackTrace();
}
}
}
return result;
}
我想在 ssh上从数据库上的信息登陆 但是query感觉写的有问题
表是 person [id username password]
想返回一个result =true; 感觉query那写的不对 求指教