Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, hoping someone can help.....ple

Status
Not open for further replies.

dthomas31uk

Technical User
Oct 19, 2003
107
GB
Hi, hoping someone can help.....please!

Iam creating classes for an internet banking site.

I have a class called clientUser and a class called company. I am having problems creating the company class. What I want to do is to only allow a user to view information from the company class if the companyId in the user class equals the company ID in the company class. My client user class looks like this

public class ClientUser{


private long userID;
//private Company company;
private long companyID;
private String username;
private String password;
private String firstname;
private String surname;
private String email;

public ClientUser(long userID,long companyID,
String username,String password,
String firstname,String surname,
String email){

this.userID = userID;
this.companyID = companyID;
this.username = username;
this.password = password;
this.firstname = firstname;
this.surname = surname;
this.email = email;
}

public long getUserID(){
return userID;
}

public long getCompanyID(){
return companyID;
}
public String getUsername(){
return username;
}

public String getPassword(){
return password;
}
public String getFirstname(){
return firstname;
}
public String getSurname(){
return surname;
}
public String getEmail(){
return email;
}
}

The following is where all the database information gets sorted out
public class DBSelector {

private static Connection conn;

static{
try{
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection("jdbc:eek:racle:thin:mad:localhost:1521:project", "darrent", "password");
}catch(ClassNotFoundException notfound){
System.out.println("Oracle class not found - check your CLASSPATH variable");
}catch(SQLException sqle){
System.out.println("SQLException thrown making connection");
System.out.println(sqle.getMessage());
}
}

public static ClientUser getClientUserByUsername(String username){
ClientUser user = null;

//the conn.createStatement() method throws a SQLException
//therefore we must catch and handle this exception approprately
try{
Statement stmt = conn.createStatement();
String sql = "Select user_id, company_id, user_name,user_password, first_name,surname,email_address from users where user_name='" + username + "'";
ResultSet rs = stmt.executeQuery(sql);

//should only return one row
//TODO: Add checking for one row only, and throw exception if more than one
if(rs.next()){
String usernameFromDB = rs.getString("user_name");
long userID = rs.getLong("user_id");
long companyID = rs.getLong("company_id");
String password = rs.getString("user_password");
String firstname = rs.getString("first_name");
String surname = rs.getString("surname");
String email = rs.getString("email_address");


user = new ClientUser(userID, companyID,usernameFromDB,

I need a company method in here can anyone help me out cheers.





 
The Company class needs a method to validate the clientUser

public boolean isAllowed(ClientUser cu){
return cu.getCompanyId()==getCompanyId();
}

then to get Company info

the client should have a method to do this:
String getCompanyInfo(Company company){
if(isAllowed){
return company.getInfo();
}else{
return "You are not allowed";
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top