• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to update a data in database from jsp

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have some user details in MySQL,iam trying to update the data from jsp page but its showing unable to connect to database but the same code if i gave some name in code it is updating, but i need to update data at run time i will give first_name in run time by useing that remaing data wants to update in mysql





if i gave code like this it is updateing



it is updating arun data but i need to give the name also in run time.


please guide me,

Thanks in advance
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
few Things I can suggest after looking into your code ...

1. pstatement.setString(2, lname); you have just set lname only even in your query you should pass fname also.
2. try to use normal sql update ,i doubt you can pass dynamic value in where clause in PL/SQL (I guess). try to update data without using where clause ,if you get success
it means you can't pass dynamic value for where clause.

hope my finding help you :)
 
Bartender
Posts: 2268
20
Android Java ME Eclipse IDE Java
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use java code inside jsp. It's a very old practice. JSP is just the view.
 
Ranch Hand
Posts: 153
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is old practice to write java code in the JSP

But if you still want to update data .Write the updation block(java code) in separate method in the Java class and then call it from the JSP.

you have to just pass the parameters in the method and rest of work you can do the method , I mean if you have only parameter then pass other one as empty and in the java method you can actually create the query having one where condition.

say
method( param1,param2){

SQL="......"

if(param1 !=""){

SQL =SQL+"fname=" +param1;
}


if(param2 !=""){

SQL =SQL+"lname=" +param1;
}

}

Something like above pseudocode..


 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic