• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

Birthday as Integer

Elite Diviner
Joined
Jul 13, 2008
Messages
419
Reaction score
217
In all packets where birthday is used it's sent to the server as Integer, so why not reading it like that from database instead of parsing it as Calendar?

Code:
private int birthday;

Code:
try {
	PreparedStatement ps = con.prepareStatement("SELECT `id`, `password`, `birthday` + 0 AS `bday` FROM `accounts` WHERE `name` = ?");
	ps.setString(1, name);
	ResultSet rs = ps.executeQuery();

	if (rs.next()) {
		id = rs.getInt("id");
		birthday = rs.getInt("bday");
		...

Code:
public boolean validateBirthday(int birthday) {
	return birthday == this.birthday;
}

Nothing special, should be clear what to do.
 
Last edited:
Experienced Elementalist
Joined
Jun 8, 2008
Messages
275
Reaction score
4
Not quite entirely sure what it does, but it sounds like instead of reading as 1992-05-17 it will read as 19920517?
 
Elite Diviner
Joined
Jul 13, 2008
Messages
419
Reaction score
217
Not quite entirely sure what it does, but it sounds like instead of reading as 1992-05-17 it will read as 19920517?

Exactly, the +0 leaves out the - so you can read it as Integer from database and don't have to create a new Calendar object for it. This also makes it easier to validate the birthday, considering that the validate function on most sources fails so much that it returns false sometimes (not always) when the birthday is correct.
 
Last edited:
Everything is possible~
Loyal Member
Joined
Jan 9, 2008
Messages
818
Reaction score
847
Good idea, using less resources for such simple things :)
 
Back
Top