This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

little bug in changing password..

 
jyotsana dang
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
jyotsana dang
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic