这是Student类
package JDBCTest;
import java.util.Date;
public class Student {
private int id;
private String name;
private boolean gender;
private Date birthday;
public Student() {
}
public Student(int id, String name, boolean gender, Date birthday) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isGender() {
return gender;
}
public void setGender(boolean gender) {
this.gender = gender;
}
public Date getBirthday(java.sql.Date birthday) {
return this.birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name='" + name + '\'' +
", gender=" + gender +
", birthday=" + birthday +
'}';
}
}
package JDBCTest;
import java.sql.*;
public class Demo6 {
public static void main(String[] args) throws SQLException {
Student student = new Student();
Connection conn = JdbcUtil.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from stu1 where id =?");
ps.setInt(1,2);
ResultSet rs = ps.executeQuery();
if (rs.next()){
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setGender(rs.getBoolean("gender"));
student.getBirthday(rs.getDate("birthday"));
}
System.out.println(rs.getDate("birthday"));
JdbcUtil.close(conn, ps, rs);
System.out.println(student);
}
}
为什么这段代码中rs.getDate("birthday")读取是正常的,但是
student.getBirthday(rs.getDate("birthday"));读取出来的却是null值?