hi everybody me Epsan and i am new to java i have a problem in validattion my code is

Joined
Mar 17, 2011
Messages
1
Reaction score
0
// User Bean
package ritt;

import java.sql.*;
import java.util.*;


public class UserBean
{
private String lname;
private String pwd;

public void setLname(String lname)
{ this.lname = lname; }

public String getLname()
{ return lname; }

public void setPwd(String pwd)
{ this.pwd= pwd; }

public String getPwd()
{ return pwd; }

public boolean login()
{
boolean logged = false;
Connection con = null;
PreparedStatement ps = null;
try
{
con = DBUtil.getConnection();
ps = con.prepareStatement("select lname from users where lname = ? and pwd= ?");
ps.setString(1,lname);
ps.setString(2,pwd);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
if(lname.equals(rs.getString(1)) && pwd.equals(rs.getString(2)))
{
logged=true;
}
}
}

catch(Exception ex)
{
System.out.println( ex.getMessage());
}
finally
{
clean(con,ps);
}
return logged;
} // end of login

public void clean(Connection con, PreparedStatement ps)
{
try
{
if ( ps != null ) ps.close();
if ( con != null) con.close();
}
catch(Exception ex)
{ System.out.println(ex.getMessage()); }
}

public boolean updatePassword(String newpwd)
{
Connection con = null;
PreparedStatement ps= null;

try
{
con = DBUtil.getConnection();
String cmd = "update users set pwd=? where lname = ? ";

ps = con.prepareStatement(cmd);
ps.setString(1,newpwd);
ps.setString(2,lname);

int cnt = ps.executeUpdate();
if ( cnt==1 )
{
pwd = newpwd;
return true;
}
else
return false;

}
catch(Exception ex)
{
System.out.println( ex.getMessage());
return false;
}
finally
{
clean(con,ps);
}


} // end of updatePassword

} // end of bean



database

table users
column-----> lname pwd
values -----> admin a

:guru:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,056
Messages
2,570,441
Members
47,119
Latest member
NoeliaIrby

Latest Threads

Top