Bookmark Topic Watch Topic
  • New Topic

Edit or update

 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
String Firstname = request.getParameter("FirstName");
String Lastname= request.getParameter("LastName");
String Username = request.getParameter("username");
String Password= request.getParameter("password");
int Psid= Integer.parseInt(request.getParameter("psid"));
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "admin@123");
PreparedStatement pst = connection.prepareStatement("update user set FirstName=?,LastName=?,username=?,password=? , psid=? where username ='?'");
pst.setString(1,Firstname);
pst.setString(2,Lastname);
pst.setString(3,Username);
pst.setString(4,Password);
pst.setInt(5,Psid);
int i = pst.executeUpdate();
if(i!=0){
pw.println("record updated");


}
else{
pw.println("failed to update the data");
}
}


this is my servlet my records are not gettng dynamiclly updated.....it is coming to else part failed to update the data...where am i wrong...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
what else will come then
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Remaining part of the code will be same. The problem in your code was pst.setString(6,Username); was missing, and you don't need where username = '?' it should be where username = ? without quotes.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
Dear i have done that and its giving me parameter exception...no of index sort of
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Post that part of the code once again, and what exact error does it show?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
String Firstname = request.getParameter("FirstName");
String LastName= request.getParameter("LastName");
String Username = request.getParameter("username");
String Password= request.getParameter("password");
int Psid= Integer.parseInt(request.getParameter("psid"));

Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "admin@123");


PreparedStatement pst = connection.prepareStatement("update user set FirstName=?,LastName=?,username=?,password=? , psid=? where username = ?");


pst.setString(1,Username);
pst.setString(2,Password);
pst.setString(3,Firstname);
pst.setString(4,LastName);
pst.setInt(5,Psid);
pst.setString(6,Username);
int i = pst.executeUpdate();

if(i!=0){
pw.println("record updated");


}
else{
pw.println("failed to update the data");
}
}
catch (Exception e){
pw.println(e);
}
}



now its showing http post method error
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is it http post is not supported by this url error or something else?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yes the same
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Post the complete servlet code and the html/jsp page that is invoking this servlet. It might be possible that the html/jsp page is using post method to invoke this servlet but you haven't implemented post method here, and please use code tags to post your code.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
this is my jsp page





servlet
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Your doPost method is not an overriden method of HttpServlet. You can't have those last two arguments here. Try this

 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yuhuuuuuuuuuuuu its running..........thnku sooooo muchhhhhhhhhhhh
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
You are welcome Akanksha .
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
sorry to disturb you again...i just want to ask you that while clicking on the edit button i need my records to get printed in textbox ...for that i need result set where should i use in my jsp or servlet
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am not disturbed at all. Now taking your question into consideration, your flow should be following. You have a edit button in the page. Once the user clicks the edit you should pass the the value to servlet based on which you have to retrieve the values from database. Once the servlet retrieves the values, it should then pass the values to jsp where the user can edit the details. Servlet and jsp have completely different usage. Servlet works in the controller layer where you typically implement your business or data access logic. Jsp works in the presentation/view layer where you just produce the output to the user.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yeah i do understand what you are saying but m asking what method should we use so that when i click my edit page in the text box values contained with that psid should get printed in the text box itself
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you show the page design/code. Where is your edit button and where which text boxes are to be replaced with the values is it in the same page or some other page. I am getting little confused.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
see what i need is..when i click the edit button it is fetching value from edit.jsp and my edit.jsp page will be viewed in that i have given fields with text box......so what i need is that if i click on edit button then it should automatically take the values from psid=<td><a href=Edit.jsp?psid=<%=resultSet.getInt("psid")%>>Edit</a> </td> and all the values of that user should get displayed in the text box...and then the user can edit what he wants.... jsp and servlet are above
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
try this in edit.jsp , although the code should have been in a servlet. Before you replace the code, keep backup of existing code.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yeah its nt working it should come in servlet and we will use a select query i think
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
As per your code

The request is going to Edit.jsp page. What exactly do you mean by not working?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
i have posted your code in my edit.jsp page.....its not taking its giving me error
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is the error?
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Wait.. I missed something. This should be the first line in Edit.jsp page, i missed the import statement.

 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
it is not taking connection resultset showing error resultset cannot be resolved
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Did you include that import statement?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yeah i included all dat before itself...and i have done ResultSet resultset = null; also still not gng
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
What is the error msg? Is it Connection can't be resolved to a type, ResultSet can't be resolved to a type and Statement can't be resolved to a type?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
resultset cannot be resolved
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
OOPs sorry..... the variable name is resultSet not resultset. s is in upper case.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yeah same thing i was about to write wink wink
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Did it work?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
ohhh you are a genius ............thnkuuuuuuuuuuuuuu
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
You are welcome once again Akanksha .
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
one more thing....when i m clicking on delete buttong it should redirect me to updated page..but it is not taking the servlet
this is my servlet and this is my jsp...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
Where is jsp? Both are servlet.
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Report post to moderator
So, it seems to be calling DeleteServlet. Have you done the required mapping in web.xml?
 
Akanksha Bhatnagar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
yeah i have done......
 
    Bookmark Topic Watch Topic
  • New Topic