replace use of select wildcard, which uses more DB resources with a call to count the number of characters an account has in CharacterService.java

This commit is contained in:
Matt Parnell
2014-08-18 22:55:02 -05:00
parent 9718715a17
commit f7512b27c3
+5 -3
View File
@@ -523,10 +523,12 @@ public class CharacterService implements INetworkDispatch {
PreparedStatement preparedStatement;
int characters = 0;
try {
preparedStatement = databaseConnection.preparedStatement("SELECT * FROM characters WHERE \"accountId\"=" + accountId + "");
preparedStatement = databaseConnection.preparedStatement("SELECT COUNT(*) AS charCount FROM characters WHERE \"accountId\"=" + accountId);
ResultSet resultSet = preparedStatement.executeQuery();
while(resultSet.next() && !resultSet.isClosed())
characters++;
characters = 0;
if (resultSet.next() && !resultSet.isClosed())
characters = resultSet.getInt("charCount");
} catch (SQLException e) {
e.printStackTrace();
}