这是用hibernate查询单表的例子:
Session dbSession = null;
try {
SessionFactory sessionFactory = new Configuration().config().buildSessionFactory();
dbSession = sessionFactory.openSession ();
Transaction transaction = dbSession.begin
Transaction();
StringBuffer hql = new StringBuffer (“from MemberTable where Name=’”);
hql.append (“userName”);
hql.append(“’”);
Query query = dbSession.createQuery (hql.toString());
query.setFirstResult(0);
query.setMaxResults(1);
transaction.commit();
Iterator memberIterator = query.iterate();
if (memberIterator.hasNext()) {
MemberTable memberObj = (MemberTable) memberIterator.next();//要是查询多表的话,在这里该怎么做?
System.out.println (memberObj.getPassword);
}
} catch (Exception e) {
System.err.println ;
} finally {
try { dbSession.close();
} catch (Exception e) {}
}