aspose file tools*
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
JavaRanch » Java Forums » Java » JSP
Bookmark "ArrayList" Watch "ArrayList" New topic
Author

ArrayList

nikunj shingala
Ranch Hand

Joined: Jul 20, 2009
Posts: 30
hi

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>();
try
{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session=sessionFactory.openSession();
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 = it.next();
staffList.add((staffCategory)row);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
session.close();
}
return staffList;
}


this code is JSP
<%
ArrayList<workCategory> workType = objallFunction.getAllStaffInfo_work();
for (workCategory workCat : workType)
{
%>
<tr>
<td>
<%= workCat.getWc_category()%>
<input type="hidden" name="hdnStaffType"/>
</td>
<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>
</tr>
<%
}

%>


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
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
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
Author
Rancher

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: http://aspose.com/file-tools
 
subject: ArrayList