Meaningless Drivel is fun!*
The moose likes JSP and the fly likes little bug in changing password.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "little bug in changing password.." Watch "little bug in changing password.." New topic
Author

little bug in changing password..

jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
wrote up this code for the user to change his password. but it always goes to the retry page??
<%@ page language="java" import="java.sql.*" session="true"%>

<%
Connection con=null;
java.sql.Statement stmt=null;
ResultSet rs=null;
boolean x=false;
boolean y=false;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();
String pass1=request.getParameter("old_pwd");
String pass2=request.getParameter("new_pwd");
String username=(String)session.getAttribute("x");
rs = stmt.executeQuery("select user_pwd from personal_info where user_pwd= "+pass1+"'");

if(rs.next())
{
x=true;
}
if(x)
{
int i=stmt.executeUpdate("UPDATE personal_info SET user_pwd='"+pass2+"' WHERE user_login ='"+username+"'");
y=true;
}

}
catch(Exception e)
{
System.out.println("exception in block"+e);
}
if(y)
{
%>
<jsp:forward page="password_updated.jsp" />
<%
}
else if(x==false ||y==false)
{
%>
<jsp:forward page="retry.jsp" />
<%}
%>
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
Hi...
Does it go into if(x){} statement...???
try writing your query like...


note the (\") in place of (')...
hth
MB
p.s. You should always have you business logic residing in you Java Bean.
[ November 06, 2003: Message edited by: Malhar Barai ]

Malhar Barai
SOA & Java Book
jyotsana dang
Ranch Hand

Joined: Sep 26, 2003
Posts: 135
Hi.. tks for the reply.. me quite a novice in jsp and stuff so have to learn a lot abt the mvc archi..
tried ur suggestions.. but the page still goes to the retry.jsp pag
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If you gt an exception of any type, y is false, an exception message is printed to standard out, and the redirect page will always be displayed.
If the driver can't be found, the retry page is shown, if the database can't be found, the retry page is shown, if the table name is wrong.... you get the picture.
Remove the try/catch block and see what happens. If an exception is thrown (and that's my guess) you'kll see the default error page with the exception details.
Dave
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hey...
outside your try catch block, the value of x & y are indeed going to remain false....
extend your try catch block to include your if statements too..so they will get the value.
this should work...
MB
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No no no, the values of x and y can be changed to true as long as the code works, but I'm not sure we've proved that yet.
Extending the try/catch block is the wrong thing to, since it isn't "error handling", it's just "error hiding". It just prints a message and pretends everything is OK. The try/catch block has to go.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: little bug in changing password..