Hello
Is there a way to get data from the db with ConnectStudentDAO

and populate the StudentBean.java and then copy the bean over to

the model (Student.java)

Is this how it is done. I'm not sure how to work out the Cast

error.

Thanks


LoginInfoBean.java

public String loginAction(String newUser, char[] newPassword, 

String newProfile) throws ClassNotFoundException, 

InstantiationException, IllegalAccessException, 

ProfileException, LoginException, FileNotFoundException, 

IOException {
        try {
            System.out.println("in LoginInfoBean");
            LoginInfo loginInfo = new LoginInfo();
            loginInfo.setPassword(newPassword.toString());
            loginInfo.setUser(newUser);
            loginInfo.setProfile(newProfile);
            if (newProfile != null) {
                if (newProfile.equals("stu_")) {
                    Student student =new Student();
                   [b] StudentBean studentBean = (StudentBean) 

ModelUtils.getStudentUserDAO();[/b]
                    studentBean.setLoggedIn(true);
                    ModelUtils.copy(studentBean, student);
                    return "profile";
                }

output

run:
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
in bCreatedTables:
created table: createAdminTable
created table: createPayeeTable
created table: createStudentTable
created table: createInstructorTable
created table: createBookingTable
created table: createInstrAvailableTable
created table: createInstrumentTable
created table: createLocationTable
created table: createPaymentTable
created table: createPayrollTable
created table: createUserTable
created table: createUserGroupMappingTable
created table: createUserGroupTable
driver tableName from xml: org.apache.derby.jdbc.EmbeddedDriver
db and tables created: 
inserted data int: insertAdminTable
inserted data int: insertPayeeTable
inserted data int: insertStudentTable
inserted data int: insertInstructorTable
inserted data int: insertPaymentTable
inserted data int: insertUserTable
inserted data int: insertUserGroupTable
inserted data int: insertUserGroupMappingTable
CONECTION IS GOOD FOR A TEST
test string query: SELECT * FROM student

number of columns: 15
, STU_UID, STU_PASSWORD, STU_LNAME, STU_MNAME, STU_FNAME, 

STU_GENDER, STU_AGE, STU_START_DATE, STU_END_DATE, STU_ADDRESS, 

STU_STATE, STU_ZIP, STU_AREA_CODE, STU_PHONE, PAYEE_UID
, sj, s, null, null, Johnny, null, null, null, null, null, null, 

null, null, null, null
, ss, s, null, null, Suzie, null, null, null, null, null, null, 

null, null, null, null
in StudentDAO.JAVA and in  connect of the ConnectDerbyDAO
returns isConnected: true
in LoginInfoBean
set password: [C@1cda59b
set user: sj
set profile: stu_
Exception in thread "main" java.lang.ClassCastException: 

model.dao.ConnectStudentDAO cannot be cast to 

view.bean.StudentBean
        at 

view.bean.LoginInfoBean.loginAction(LoginInfoBean.java:43)
        at 

view.SchoolJDesktopPane.login(SchoolJDesktopPane.java:183)
        at 

view.SchoolJDesktopPane.<init>(SchoolJDesktopPane.java:118)
        at view.Main.createJDesktopPane(Main.java:43)
        at view.Main.main(Main.java:38)
Java Result: 1
BUILD SUCCESSFUL (total time: 19 seconds)

Student.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.util.Date;

/**
 *
 * @author depot
 */
public class Student extends LoginInfo implements 

java.io.Serializable{
    
    public boolean student=true;
    public boolean teacher=false;
    public boolean admin=false;
    public boolean payee=false;
    public String uid;    
    public String fName;
    public String lName;
    public String mName;
    public String gender;
    public Date startDate;
    public Date endDate;
    public int age;
    public String address;
    public String state;
    public int zip;
    public int areaCode;
    public int phone;
    public String payeeUid;
    public String location;
    public Double payRate;
    public int bookNum;
    public String stuUid;
    public int rate;



    public Student(){

    }

    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    public boolean isPayee() {
        return payee;
    }

    public void setPayee(boolean payee) {
        this.payee = payee;
    }

    public boolean isStudent() {
        return student;
    }

    public void setStudent(boolean student) {
        this.student = student;
        System.out.println("in model: "+student);
    }

    public boolean isTeacher() {
        return teacher;
    }

    public void setTeacher(boolean teacher) {
        this.teacher = teacher;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(int areaCode) {
        this.areaCode = areaCode;
    }

    public int getBookNum() {
        return bookNum;
    }

    public void setBookNum(int bookNum) {
        this.bookNum = bookNum;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getlName() {
        return lName;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getmName() {
        return mName;
    }

    public void setmName(String mName) {
        this.mName = mName;
    }

    public Double getPayRate() {
        return payRate;
    }

    public void setPayRate(Double payRate) {
        this.payRate = payRate;
    }

    public String getPayeeUid() {
        return payeeUid;
    }

    public void setPayeeUid(String payeeUid) {
        this.payeeUid = payeeUid;
    }

    public int getPhone() {
        return phone;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getStuUid() {
        return stuUid;
    }

    public void setStuUid(String stuUid) {
        this.stuUid = stuUid;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
        System.out.println("in model: "+uid);
    }

    public int getZip() {
        return zip;
    }

    public void setZip(int zip) {
        this.zip = zip;
    }

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
        System.out.println("in model: "+fName);
    }

    public int getRate() {
        return rate;
    }

    public void setRate(int rate) {
        this.rate = rate;
    }

}

StudentBean.java

package view.bean;
import model.Student;

/**
 *
 * @author depot
 */
public class StudentBean extends Student{

    public transient boolean loggedIn = false;

    public boolean isLoggedIn() {
        return loggedIn;
    }

    public void setLoggedIn(boolean loggedIn) {
        this.loggedIn = loggedIn;
    }

 

}

ConnectStudentDAO.JAVA

public class ConnectStudentDAO implements StudentDAO{
    public String type;
    public Student newUser;
    public LoginInfo loginInfo;    
    public Student studentUser;
    public ConnectStudentDAO(){

    }
    

////////////////////////////////////////////////////////////////

//////
    //////////////////  login find user 

/////////////////////////
    

////////////////////////////////////////////////////////////////
   public Connection conn=null;
  
    public void ConnectStudent() throws 

UnknownSubscriberException, SQLException, 

IncorrectPasswordException, LoginException, 

FileNotFoundException, IOException{
         System.out.println("in ConnectStudentDAO");
        DerbyDAOFactory ddf =new DerbyDAOFactory();
        conn=(Connection)ddf.getConnection();

        PreparedStatement ps = null;

            //conn = dataSource.getConnection();
            ps = (PreparedStatement) conn.prepareStatement(
                    

ModelUtils.getXMLResource("SelectUserGroup"));

            //[b]
            //SelectUserGroup will return the user group related
            /*
             * <entry key="SelectUserGroup"> SELECT groupName 

FROM usergroup AS ug,usergroup_mapping
    AS ugm WHERE  ugm.uid">? AND ugm.groupid">ug.groupid 

</entry>
             */
            //[/b]
            //ps.setString(1, loginInfo.getEmail());
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                throw new UnknownSubscriberException();// no 

exceptions are good
            }

            String groupName = rs.getString(1);
           
           
            
            if (groupName.equals("student")) {
                setType("student");

                Student studentUser = select();

                newUser = studentUser;
                select();

            }
    }
     public Student select() throws UnknownSubscriberException, 

IncorrectPasswordException, LoginException, SQLException, 

FileNotFoundException, IOException {
        Connection conn = getConn();

        PreparedStatement ps = null;


            //conn = dataSource.getConnection();

            ps = (PreparedStatement) conn.prepareStatement(
                    

ModelUtils.getXMLResource("SelectStudent"));
            //ps.setString(1, loginInfo.getEmail());
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                throw new UnknownSubscriberException();// no 

exceptions are good
            }
            String uid = rs.getString(1);


            if (!loginInfo.getUser().equals(uid)) {
                throw new UnknownSubscriberException();
            }

            String password = rs.getString(2);
            if (!loginInfo.getPassword().equals(password)) {
                throw new IncorrectPasswordException();
            }

            
            ///////////////// test output 

//////////////////////////
            ///////////////// test output 

//////////////////////////
            System.out.println(uid);                          

/////
            System.out.println(password);                      

/////
            Properties 

dbProperties=ModelUtils.loadXMLResources();///
            DBOut o =new DBOut();               

//////////////////////
            o.testOutput(conn,dbProperties);    

//////////////////////
            ///////////////// test output 

//////////////////////////
            ///////////////// test output 

//////////////////////////

            //newUser.setEmail(loginInfo.getEmail());
            studentUser.setUid(rs.getString(uid));
            studentUser.setPassword(password);
            studentUser.setlName(rs.getString(3));
            studentUser.setmName(rs.getString(4));
            studentUser.setfName(rs.getString(5));
            studentUser.setGender(rs.getString(6));
            studentUser.setStartDate(rs.getDate(7));
            studentUser.setEndDate(rs.getDate(8));
            studentUser.setAge(rs.getInt(9));
            studentUser.setAddress(rs.getString(10));
            studentUser.setState(rs.getString(11));
            studentUser.setZip(rs.getInt(12));
            studentUser.setAreaCode(rs.getInt(13));
            studentUser.setPhone(rs.getInt(14));
            studentUser.setPayRate(rs.getDouble(15));

            return studentUser;

    }
////////////////////////////////////////////////////////////////

//////
    ////////////////// end login 

////////////////////////////////////
    

////////////////////////////////////////////////////////////////

I have already changed every thing
sorry
the new code is using a DAOFactory and the the objects passed are different

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.