Hello all.
The Java Date and time classes are difficult.
I think I have to use java.sql.Date which is a sub
class of Date but is not a date unless the time is normalized to zero.
so I've heard.
I would like to work with my studentDOB first by collecting
a JFormatted field/put it in the bean /get the value from the bean/
put it back into the JFormatted textField.
I have DAO classes to collect and put results back to a form
Could someone help me get started with an example?
I use a JFormattedTextField that collect a obj as 12/31/2011. I don't
need mm,ss ect unless it is easier to start with
To collect the data to set the studentDOB I use
if (i == 7) {
studentBean.setDob((Date) (txtFieldArray[i].getValue()));//format wanted 12/31/2011
}
I setString using
Just testing it using the :
----> ps.setDate(7, (java.sql.Date) studentUser.getDob());<----working with this one for now
@Override
public boolean insertStudent() throws FileNotFoundException, IOException, SQLException {
boolean insert = true;
studentUser = MasterRegisterForm.studentBean;
setTableName(tableName);
try {
conn = connect();
ps = (PreparedStatement) conn.prepareStatement(
ModelUtils.getXMLResource("insertStudent"));
ps.setString(1, studentUser.getNewUserUid());
ps.setString(2, studentUser.getNewUserPassword());
...
----> ps.setDate(7, (java.sql.Date) studentUser.getDob());<----working with this one for now
...
ps.setString(14, studentUser.getEmail());
int rowCount = ps.executeUpdate();
if (rowCount != 1) {
insert = false;
close(conn, ps);
throw new RegisterException();
} else {
close(conn, ps);
throw new SuccessfullRegistrationMessage();
}
} catch (InterruptedException ex) {
Logger.getLogger(StudentSupplementalDAO.class.getName()).log(Level.SEVERE, null, ex);
} catch (RegisterException e) {
insert = false;
String x = e.getMessage();
System.out.println("error message is: " + x);
ViewUtils vu = new ViewUtils();
vu.addExceptionMessage(x);
} catch (SuccessfullRegistrationMessage e) {
String x = e.getMessage();
System.out.println("Curtasy message is: " + x);
ViewUtils vu = new ViewUtils();
vu.addMessage(x);
} finally {
try {
close(conn, ps);
} catch (SQLException e) {
ModelUtils.log(e);
}
}
return insert;
}
I then go to the db and get the DOB need to put it back into the JFormatted
textField using:
Just testing it using the :
StudentProfileForm.txtFieldArray[7].setValue(studentUser.getDob());<-----this one
code:
public void fillFieldsProfileForm() {
...
--> StudentProfileForm.txtFieldArray[7].setValue(studentUser.getDob());<-----this one
...
}
Relative output:
<entry key="createStudentTable"> CREATE TABLE student (
stu_uid VARCHAR(70) PRIMARY KEY,
stu_password VARCHAR(50),
stu_lname VARCHAR(90),
stu_mname VARCHAR(90),
stu_fname VARCHAR(90),
stu_gender VARCHAR(1),
stu_dob DATE,
stu_start_date DATE,
stu_area_code VARCHAR(5),
stu_phone VARCHAR(70),
stu_address VARCHAR(90),
stu_state VARCHAR(2),
stu_zip VARCHAR(7),
<!-- payee_uid VARCHAR(70) CONSTRAINT PAYEE_FK REFERENCES payee, -->
stu_email VARCHAR(90)
)
<entry key="selectStudent">SELECT
stu_uid,
stu_password,
stu_lname,
stu_mname,
stu_fname,
stu_gender,
stu_dob,
stu_start_date,
stu_address,
stu_state,
stu_zip,
stu_area_code,
stu_phone,
<!--
payee_uid,
-->
stu_email
FROM student
WHERE stu_uid=?
</entry>
CREATED NEW INSTANCE OF ConnectStudentDAO
name: STU_UID
name: STU_PASSWORD
name: STU_LNAME
name: STU_MNAME
name: STU_FNAME
name: STU_GENDER
name: STU_DOB
name: STU_START_DATE
name: STU_AREA_CODE
name: STU_PHONE
name: STU_ADDRESS
name: STU_STATE
name: STU_ZIP
name: STU_EMAIL
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: DATE
value: DATE
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
value: VARCHAR
Error
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
at view.formActions.ProfileFormActions.studentProfileAction(ProfileFormActions.java:630)