the problem here is though i m getting right values from databut the
authentication(String username2,String password2)
is always returning false value
i passed the values in this method
login status<%=login.authenticate(u1,p1)%>
where u1 & p1 are
<%String u1=request.getParameter("username");
String p1=request.getParameter("password");
%>
which is passed here from login1.jsp
the authentication method is
public boolean authenticate(String username2, String password2)
{
Connection con= null;
Statement stmt = null;
ResultSet rs = null;
String DbUserName="";
String DbPassword="";
String finalUser="";
try {
Context initctx = new InitialContext();
Context envctx = (Context)initctx.lookup("java:comp/env");
DataSource ds = (DataSource)envctx.lookup("jdbc/inventory");
con = ds.getConnection();
String query="select * from Registration;";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
rs.next();
while(rs.next())
{
DbUserName=rs.getString(1);
DbPassword=rs.getString(2);
if (username2.equals(DbUserName) && password2.equals(DbPassword))
{
break; }
}
return true;
}
catch(Exception e)
{ e.printStackTrace();
return false;
}
/*
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package beans;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class Login
{
private String username = "";
private String password = "";
public Login()
{
}
public void setUsername(String username)
{
this.username = username;
}
public void setPassword(String password)
{
this.password = password;
}
public String getUsername()
{
return username ;
}
public String getPassword()
{
return password;
}
public boolean authenticate(String username2, String password2)
{
Connection con= null;
Statement stmt = null;
ResultSet rs = null;
String DbUserName="";
String DbPassword="";
String finalUser="";
try {
Context initctx = new InitialContext();
Context envctx = (Context)initctx.lookup("java:comp/env");
DataSource ds = (DataSource)envctx.lookup("jdbc/inventory");
con = ds.getConnection();
String query="select * from Registration;";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
rs.next();
while(rs.next())
{
DbUserName=rs.getString(1);
DbPassword=rs.getString(2);
if (username2.equals(DbUserName) && password2.equals(DbPassword))
{
break; }
}
return true;
}
catch(Exception e)
{ e.printStackTrace();
return false;
}
}
}