如何用hibernate直接进行SQL语句查询 20
1个回答
2017-08-23
展开全部
如何用hibernate直接进行SQL语句查询
public int getLogin(String username,String password)
{ String sql="select * from user_table where username=? and password=?";
SQLQuery query=getSession().createSQLQuery(sql).addEntity(UserTable.class);
query.setString(0,username);
query.setString(1,password);
return Integer.parseInt(query.uniqueResult().toString());
}
public static void main(String[] args) {
new UserTableDAO().getLogin("zhang","yuan");
}
public int getLogin(String username,String password)
{ String sql="select * from user_table where username=? and password=?";
SQLQuery query=getSession().createSQLQuery(sql).addEntity(UserTable.class);
query.setString(0,username);
query.setString(1,password);
return Integer.parseInt(query.uniqueResult().toString());
}
public static void main(String[] args) {
new UserTableDAO().getLogin("zhang","yuan");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询