Reputation: 57
here is my servlet code...
try {
HttpSession session=request.getSession(true);
String FN= (String)session.getAttribute("FN");
String h1= request.getParameter("h1"); //contains the password value
if(h1=="" || h1== null)
{
response.sendRedirect("PERROR.html"); // if no value in passwrd field
}
else{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn2");
Statement st=con.createStatement();
String UNM= (String)session.getAttribute("uname");
String query= "select * from img_pwd where uname='"+UNM+"' and pwd='"+h1+"')";
// validating from the table img_pwd
ResultSet r= st.executeQuery(query);
if(r.next())
{
con.close();
response.sendRedirect("ACCOUNT.jsp"); //success, go to dashboard
}
else
{
response.sendRedirect("PERROR.html"); // if the password-mismatches
}
}
} finally {
out.close();
}
and the table "img_pwd" is shown below--
1. uname(nvarchar[50])
2. pwd(nvarchar[20])
So i have tried debugging and found that program execution reaches till where the query is stored in a string, but the query is not executed and the progress of the program stops just after storing the QUERY STRING....
i CANT FIGURE OUT THE ERROR, NEED HELP..
Upvotes: 0
Views: 575
Reputation: 1945
Yes remove ")" from
"select * from img_pwd where uname='"+UNM+"' and pwd='"+h1+"')"
Your query string should be like this:
select * from table
Upvotes: 0
Reputation: 37576
You can try the following:
select * from table
where you are sure there should be some results to ensure your access to the database is working as expected."%"
Upvotes: 0
Reputation: 57
well it seems funny...but i have now realised that i wasted my 5 hours just because of a single closing bracket.. )
"select * from img_pwd where uname='"+UNM+"' and pwd='"+h1+"')"
can u figure out the ")"..??? Yes, that was the mistake. after removing it the code is working fine.
Upvotes: 1
Reputation: 192
may be there is any exception while connecting with database you did not mentioned catch block so put a catch and debug.
Upvotes: 0