• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList

 
nikunj shingala
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49813
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp is far away from hibernate,since we do not know about hibernate
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The query already returns a list; why do you do anything w/ the query and staffList after query.list()???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic