aspose file tools*
The moose likes Spring and the fly likes Spring updates more than one row Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring updates more than one row" Watch "Spring updates more than one row" New topic
Author

Spring updates more than one row

Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61

Hi

Can anyone please help me how to update more than one rows using JdbcTemplate


I have query like this


UPDATE EMPLOYEE SET STATUS='REGISTERED' WHERE EMP_ID IN (:empids)


I want to update the status as registered for the employee ids...


How can we achieve this in spring...

Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

What is this method ?


Ashwin Sridhar
SCJP | SCWCD | OCA
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
Method used to execute the query..

I want to pass the list of employee ids and status.. FOr this I need 2 parameters. so inside the method, i declared 2 parameters.

I want to know how to execute the query using NamedParameterJdbcTemplate. I found one example below

But this query for select all the ids from the table. But i want to update the status for all the employee ids.
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

You could some details on this link. Doc
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
I want to update the employee status as "Registered"

for the list of employee ids.. I tried with the below

code.. But update command gets hanged..

Can anyone please help me to complete this..


From Servlet I passed the List of values to the

updateEmployeeStatus:

ArrayList<String> empidList =new ArrayList<String>();

empidList.add("1");
empidList.add("2");
empidList.add("3");

Method in Employee Status class:
--------------------------------

public boolean updateEmployeeStatus(List<String> empIdlist)
{

String query="UPDATE EMPLOYEE SET STATUS='Registered'
WHERE EMP_ID IN(:empids);

Employee e=new Employee();

e.setEmpIDList(empIdlist);

Map<String,Object> params=new HahMap<String,Object>();

params.put("empids",e.getEmpIDList); ------------> Passing employee ids to the IN clause...

int count=getNamedParameterJdbcTemplate().update
(query,params); ----------> gets hanged..

}
Booma Devi
Ranch Hand

Joined: Nov 02, 2011
Posts: 61
Problem solved...
 
jQuery in Action, 2nd edition
 
subject: Spring updates more than one row