Ads Inside Post

Search in This Blog

Show records without class in hibernate and struts

Show all records without pojo class in hibernate and struts

Struts and Hibernate if you need to show all records from database table then you need to create a pojo some cases you not need to use pojo class then how can you achieve to show all records? I have faced the same problem and overcome it with listed below code.

In query.hbm.xml file
<sql-query name="TestTestTest">
select user_name, user_id, password, cd, user_status,CAST(from_dt AS CHAR) as from_date from user_info

In your action class

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.*;
import plugins.HibernateSessionFactory;

Session ssn = null;
ssn = HibernateSessionFactory.getSession();
Query qry = ssn.getNamedQuery("TestTestTest");
List <Object[]>containerResults = qry.list();
for(java.lang.Object[] result : containerResults) {