package userstruts;

import java.sql.*;
import javax.sql.DataSource;

public class UserBean {
  Connection connect = null;
  ResultSet rs = null;
  String usn, psd;
  boolean b = false;
  public UserBean(DataSource dataSource) {
    try {
      connect = dataSource.getConnection();
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
  }

  public boolean verifyUser(String userName, String password) {
    String sql = "select * from Users where username='" + userName +
        "' and password='" + password + "'";
    try {
      Statement stmt = connect.createStatement();
      rs = stmt.executeQuery(sql);
      while (rs.next()) {
        b = true;
      }
      if (connect != null) {
        try {
          connect.close();
          connect = null;
        }
        catch (SQLException ex) {
          System.err.println(ex.getMessage());
        }
      }
    }
    catch (SQLException ex) {

      ex.printStackTrace();
    }
    return b;
  }
}
