Java数据访问对象获取GregorianCalendar
我一直很难把公历印在我的代码上,当我试图把它印在代码上时,它给了我一个非法的例外 下面的代码是我的构造函数Java数据访问对象获取GregorianCalendar,java,dao,gregorian-calendar,Java,Dao,Gregorian Calendar,我一直很难把公历印在我的代码上,当我试图把它印在代码上时,它给了我一个非法的例外 下面的代码是我的构造函数 private int _identifier; private String _fName; private String _lName; private String _emailAddress; private String _gamerTag; private GregorianCalendar _birthDate; public Player(int identifier,
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);
以及生日的静态对象
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]
希望这有帮助
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。您的意思是这样的吗?players.setBirthDate(resultSet.getDate(BIRTHDATE));当我这样做的时候,我得到了一个illegalargumentexception,而
resultSet.getDate(BIRTHDATE)
返回的是什么?resultSet到底是什么?它没有在您显示的代码示例中的任何地方定义。ResultSet ResultSet=statement.executeQuery(sqlString);这是resultSet请编辑您的问题以添加resultSet
的定义,以便您的问题完整且易于阅读。我已更新了resultSet的定义