Java数据访问对象获取GregorianCalendar

时间:2015-03-01 19:26:01

标签: java dao gregorian-calendar

我一直无法尝试在我的代码上打印格里高利历,当我尝试将其设置为IllegalArgumentException时。

下面的代码是我的构造函数

private int _identifier;
private String _fName;
private String _lName;
private String _emailAddress;
private String _gamerTag;
private GregorianCalendar _birthDate;

public Player(int identifier, String fName, String lName,
    String emailAddress, String gamerTag, GregorianCalendar birthDate) {

    _identifier = identifier;
    _fName = fName;
    _lName = lName;
    _emailAddress = emailAddress;
    _gamerTag = gamerTag;
    _birthDate = birthDate;

这里是我的吸气者和二传手

/**
 * @return the birthDate
 */
public GregorianCalendar getBirthDate() {
    return _birthDate;
}


/**
 * @param string the birthDate to set
 */
public void setBirthDate(GregorianCalendar birthDate) {
    _birthDate = birthDate;
}

/**
 * @param birthDate the birthDate to set
 */
@Deprecated
public void setBirthDate(Date date) {
    _birthDate = new GregorianCalendar();
}

/*
 * Set the birthdate
 * 
 * @param year the year, includes the century, ex. 1967
 * @param month the month - must be 0-based
 * @param day the day of the month - 1-based
 */
public void setBirthDate(int year, int month, int day) {
    _birthDate = new GregorianCalendar();
    _birthDate.set(Calendar.YEAR, year);
    _birthDate.set(Calendar.MONTH, month);
    _birthDate.set(Calendar.DAY_OF_MONTH, day);
}

跟进是我的数据访问对象代码,其代码为我提供了错误

            String sqlString = String.format("SELECT * FROM %s WHERE %s  = '%s'", _tableName, GAMERTAG , gamertag);
            ResultSet resultSet = statement.executeQuery(sqlString);
            players = new Player();
            players.setIdentifier(resultSet.getInt(ID));
            players.setfName(resultSet.getString(FIRSTNAME));
            players.setlName(resultSet.getString(LASTNAME));
            players.setEmailAddress(resultSet.getString(EMAIL));
            players.setGamerTag(resultSet.getString(GAMERTAG));
            resultSet.getDate(BIRTHDATE);

和BIRTHDATE的静态对象

public static final String TABLE_NAME  = "Players";
public static final String ID = "ID";
public static final String FIRSTNAME = "FIRSTNAME";
public static final String LASTNAME = "LASTNAME";
public static final String EMAIL = "EMAIL";
public static final String GAMERTAG = "GAMERTAG";
public static final String BIRTHDATE = "BIRTHDATE";

我想要它的结果如下面的代码

2001-10-03T00:00:00.000Z
Player [id=4, firstName=Jeanette, lastName=Price, emailAddress=priceizrite@hotmail.com, gamerTag=Quinesia, birthDate=java.util.GregorianCalendar[time=1002092400000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Vancouver",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=189,lastRule=java.util.SimpleTimeZone[id=America/Vancouver,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2001,MONTH=9,WEEK_OF_YEAR=40,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=276,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-28800000,DST_OFFSET=3600000]]

这是我目前的结果

Player [identifier=4, fName=Jeanette, lName=Price, emailAddress=priceizrite@hotmail.com, gamerTag=Quinesia, birthDate=null]

希望这会有所帮助

1 个答案:

答案 0 :(得分:0)

    players = new Player();
    players.setIdentifier(resultSet.getInt(ID));
    players.setfName(resultSet.getString(FIRSTNAME));
    players.setlName(resultSet.getString(LASTNAME));
    players.setEmailAddress(resultSet.getString(EMAIL));
    players.setGamerTag(resultSet.getString(GAMERTAG));
    resultSet.getDate(BIRTHDATE);

您似乎没有为您的Player对象执行setDate,这就是为什么它总是附加null。