dthomas31uk
Technical User
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("jdbcracle:thinlocalhost:1521roject", "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.
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("jdbcracle:thinlocalhost:1521roject", "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.