Thursday, 29 August 2013

How to retrieve database table value in hibernate?

How to retrieve database table value in hibernate?

I am new to the Hibernate, i want to retrieve table values from database,
I have a code but it returns object values. My sample code is,
Configuration conf=new Configuration();
@SuppressWarnings("deprecation")
SessionFactory sessionfactory=conf.configure().buildSessionFactory();
Session session=sessionfactory.openSession();
List maintable = null;
try
{
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery ("select main.empid,main.address
from Main as main");
maintable =q.list();
Object[] obj=maintable.toArray();
for(int i=0;i<obj.length;i++)
{
System.out.println(""+maintable.get(i));
}
tx.commit();
session.close();
}
catch(Exception e1)
{
System.out.println("Exception");
}

No comments:

Post a Comment