Announcement Announcement Module
Collapse
No announcement yet.
Reading a date from a Mysql database Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading a date from a Mysql database

    I am trying to read a record from a Mysql database. One column is a date, but my object's java.sql.Date object isn't being populated. It still has null, even though all rows in the table have values for the date column. Here is my Java object.

    Code:
    public class Bulletin {
        private int id;
        private java.sql.Date day;
        private String subject;
        private String name;
        private String note;
        private boolean approved;
    
        public int getId() {
            return this.id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public java.sql.Date getDay() {
            return this.day;
        }
    
        public void setDate(java.sql.Date day) {
            this.day = day;
        }
    
        public String getSubject() {
            return subject;
        }
    
        public void setSubject(String subject) {
            this.subject = subject;
        }
    
        public String getName() {
            return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getNote() {
            return this.note;
        }
    
        public void setNote(String note) {
            this.note = note;
        }
    
        public boolean isApproved() {
            return this.approved;
        }
    
        public void setApproved(boolean approved) {
            this.approved = approved;
        }
    }
    Here is the Java command I'm using to read from the database.

    Code:
    return (Bulletin) this.getJdbcTemplate().queryForObject(
        "select * from bulletins where id = ?",
        new Object[] { id },
        new BeanPropertyRowMapper<Bulletin>(Bulletin.class));
    Here is the description of my table.

    Code:
    +----------+---------------+------+-----+---------+----------------+
    | Field    | Type          | Null | Key | Default | Extra          |
    +----------+---------------+------+-----+---------+----------------+
    | id       | int(11)       | NO   | PRI | NULL    | auto_increment |
    | day      | date          | YES  |     | NULL    |                |
    | name     | varchar(30)   | YES  |     | NULL    |                |
    | subject  | varchar(50)   | YES  |     | NULL    |                |
    | note     | varchar(2500) | YES  |     | NULL    |                |
    | approved | tinyint(4)    | YES  |     | NULL    |                |
    +----------+---------------+------+-----+---------+----------------+

  • #2
    Problem solved. It would appear BeanRowPropertyMapper doesn't work too well with java.sql.Date, so I am using a work-around.

    Comment


    • #3
      Originally posted by FHSerkland View Post
      Problem solved. It would appear BeanRowPropertyMapper doesn't work too well with java.sql.Date, so I am using a work-around.
      This annotation works well:

      Code:
      @Temporal(TemporalType.DATE)

      Comment

      Working...
      X