Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update a row using spring jdbctemplate

 
soumya dash
Greenhorn
Posts: 14
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to spring. I am developing a CRUD application using spring jdbc template. I am done with insert and select. but in update am facing some problem.
can anybody provide me a simple example of update and delete using jdbctemplate.
thnks in advance.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Insert update and delete all use the same syntax



Where the Query can be any insert, update or delete SQL statement and the objects param1 and param2 correspond to the 2 ?'s in the query that was passed in.
 
soumya dash
Greenhorn
Posts: 14
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnks.

but how to get the param value from JSP? the values to be passed from jsp to controller so that service class can implement the method with the param passed.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
soumya dash wrote:thnks.

but how to get the param value from JSP? the values to be passed from jsp to controller so that service class can implement the method with the param passed.


How are you getting it for the insert? Update would be the exact same. If you have a form for insert, you would want to use it for update too.

For delete you would probably only need the id/primary key value from the page.

Mark
 
soumya dash
Greenhorn
Posts: 14
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for insert, the pojo obj is mapped. but for update you need to map the Id of that particular row as in delete.. that's what i'm asking how to map that id by submit button.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store the objects id as a hidden field on your JSP in the same fashion that you do with the other fields. If it is null when it comes in on your controller than you know to do an insert, otherwise you will update.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic