//根据姓名查询用户信息
public Customer getOneUser(String name) {
try{
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction ts=session.beginTransaction();
String hql="from Customer where username='"+name+"'";
Query query=session.createQuery(hql);
Customer usr=(Customer) query.uniqueResult();
ts.commit();
session.clear();
return usr;
}catch(Exception e){
e.printStackTrace();
return null;
}
}这段代码有什么问题?
public Customer getOneUser(String name) {
try{
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction ts=session.beginTransaction();
String hql="from Customer where username='"+name+"'";
Query query=session.createQuery(hql);
Customer usr=(Customer) query.uniqueResult();
ts.commit();
session.clear();
return usr;
}catch(Exception e){
e.printStackTrace();
return null;
}
}这段代码有什么问题?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货