Well, you really probably want to do an HQL query, don't you?
If you're going to the trouble of setting up Hibernate, doing an SQL query is a bit of a step backwards.
Look at this tutorial on mastering HQL and Hibernate Queries:
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries
If you had a Java class POJO named User, you might do an HQL query like this:
Code:
Session session = HibernateUtil.beginTransaction();
String loginName = "mj";
String hql="from User where loginName = :name";
Query query = session.createQuery(hql);
query.setString("name", loginName);
Object o = query.uniqueResult();
User user = (User)o;
System.out.println(user.getLoginName());
HibernateUtil.commitTransaction();
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries