A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Servlets
Author
Servlet Update Code Please Help
Pranit Sonawane
Ranch Hand
Joined: Jul 29, 2011
Posts: 108
I like...
posted
Feb 16, 2013 08:12:44
0
import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import java.sql.*; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class AdminPassUpdate extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); HttpSession hs = request.getSession(false); String password = request.getParameter("currpass"); String uname = (String) hs.getAttribute("savedUserName"); if (password.equals(password)) { try { String newuname = uname; String sql = "update staff set pass = ? where uname = ?"; String newpass = request.getParameter("newpass"); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ABC_Bank", "root", "pranit"); PreparedStatement pst = con.prepareStatement(sql); pst.setString(1, newuname); pst.setString(2, newpass); pst.executeUpdate(); out.println("Updated Success"); } catch (Exception e) { out.println(e.getMessage()); } } else { hs.invalidate(); RequestDispatcher rd = request.getRequestDispatcher("index.jsp"); rd.forward(request, response); } } AdminDAO ad = new AdminDAO(); }
its going to on the another page also printing the update message but not updating the record. What can I do? Please help
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
14
I like...
posted
Feb 16, 2013 10:06:32
0
Please do not post the same question more than once.
[
Smart Questions
] [
JSP FAQ
] [
Books by Bear
] [
Bear's FrontMan
] [
About Bear
]
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Servlet Update Code Please Help
Similar Threads
Servlet Update Code
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
Using strings within strings to read vars?
Variable is not getting transferred from controller servlet to model
Login/Logout Problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter