Hello
if I create newUser which is new StudentBean() why is
StudentBean studentBean not equal newUser?
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
shutdown database
disconnected after building the database
java.sql.SQLNonTransientConnectionException: Database
'schoolofdb' shutdown.
disconnected after building the database
in LoginInfoBean
db sets password in LoginInfoBean: [C@dfcb47
db sets user in LoginInfoBean: sj
db sets profile: stu_
all models (Student.java extend LoginInfo.javaall beans extend
models
Exception in thread "main" java.lang.ClassCastException:
model.dao.ConnectStudentDAO cannot be cast to
view.bean.StudentBean
at
view.bean.LoginInfoBean.loginAction(LoginInfoBean.java:45)
at
view.SchoolJDesktopPane.login(SchoolJDesktopPane.java:183)
at
view.SchoolJDesktopPane.<init>(SchoolJDesktopPane.java:118)
at view.Main.createJDesktopPane(Main.java:44)
at view.Main.main(Main.java:39)
Java Result: 1
BUILD SUCCESSFUL (total time: 22 seconds)
public class LoginInfoBean extends LoginInfo {
public String newUser;
public String newPassword;
public String newProfile;
public String factoryKey;
public String[] factoryKeyArray;
public String newUserField;
public String passField;
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();
DerbyDAOFactory f=new DerbyDAOFactory();
StudentBean studentBean=(StudentBean)
f.getStudentDAO();
studentBean.setLoggedIn(true);
ModelUtils.copy(studentBean, student);
return "profile";
//if this returns profile then it will build
the GUI
}
//if this returns profile then it will build the GUI [b]Student student = (Student) f.getStudentDAO();[/b]
DerbyDAOFactory.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import model.ModelUtils;
/**
*
* @author depot
*/
public class DerbyDAOFactory extends DAOFactory {
public static void buildDB() throws FileNotFoundException,
IOException, SQLException {
ConnectDerbyDAO cdd = new ConnectDerbyDAO();
cdd.connect();
cdd.disconnect();
System.out.println("disconnected after building the
database");
}
public Connection getConnection() throws
FileNotFoundException, IOException, SQLException {
System.out.println("in getConnection of
DerbyDAOFactory");
ConnectDerbyDAO cdd = new ConnectDerbyDAO();
cdd.connect();
Connection conn = cdd.getConn();
return conn;
}
@Override
public AdminDAO getAdminDAO() {
return new ConnectAdminDAO();
}
@Override
public StudentDAO getStudentDAO() {
return new ConnectStudentDAO();
}
@Override
public InstructorDAO getInstructorDAO() {
return new ConnectInstructorDAO();
}
@Override
public PayeeDAO getPayeeDAO() {
return new ConnectPayeeDAO();
}
}
ConnectStudentDAO.java
find and confirm uid,profile,password access and set all fieled
in newUser which is a new Student()
and return it.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
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 StudentBean ConnectStudent() throws
UnknownSubscriberException, SQLException,
IncorrectPasswordException, LoginException,
FileNotFoundException, IOException {
System.out.println("in ConnectStudentDAO");
DerbyDAOFactory ddf = new DerbyDAOFactory();
conn = (Connection) ddf.getConnection();
PreparedStatement ps = null;
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");
studentUser = select();
newUser = studentUser;
}
return (StudentBean) newUser;
}
public StudentBean select() throws
UnknownSubscriberException, IncorrectPasswordException,
LoginException, SQLException, FileNotFoundException, IOException
{
PreparedStatement ps = null;
ps = (PreparedStatement) conn.prepareStatement(
ModelUtils.getXMLResource("SelectStudent"));
System.out.println("SelectStudent from xml: \n"
+ ModelUtils.getXMLResource("SelectStudent"));
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 (StudentBean) studentUser;
}
....
}