This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSP and the fly likes ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "ArrayList" Watch "ArrayList" New topic


nikunj shingala
Ranch Hand

Joined: Jul 20, 2009
Posts: 30

i am fresher in java and i can work on one project and that project client requirement is that when we enter any value in text box that value store in database and it display that page below

I use Netbeans and for mysql and i write this code

it is java file

public ArrayList getAllStaffInfo()
Session session=null;
ArrayList staffList = new ArrayList<staffCategory>();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
String SQL_QUERY="from staffCategory";
Query query = session.createQuery(SQL_QUERY);
staffList = (ArrayList<staffCategory>) query.list();

for(Iterator it = query.iterate(); it.hasNext();)
Object row =;
catch(Exception e)
return staffList;

this code is JSP
ArrayList<workCategory> workType = objallFunction.getAllStaffInfo_work();
for (workCategory workCat : workType)
<%= workCat.getWc_category()%>
<input type="hidden" name="hdnStaffType"/>
<td><%= workCat.getWc_desc()%></td>
<td><input type="button" id="btnedit" name="btnedit" value="Edit"/></td>
<td><input type="button" id="btndelete" name="btndelete" value="Delete"/></td>


above code is run successfully but all data store in database 1 time and display in page 2 time or multiple times same data but actually that data is store 1 time.
so please help and give write code ya give another code.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46428
You don't appear to use a database at all in that code. That doesn't look like beginner's code, so I shall move you to the JSP forum. And your code is difficult to read if you don't use the
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

jsp is far away from hibernate,since we do not know about hibernate
David Newton

Joined: Sep 29, 2008
Posts: 12617

The query already returns a list; why do you do anything w/ the query and staffList after query.list()???
I agree. Here's the link:
subject: ArrayList
jQuery in Action, 3rd edition