Skip to content

Commit

Permalink
JAMES-2251 Switch over to using ParameterMetaData.getParameterCount()
Browse files Browse the repository at this point in the history
  • Loading branch information
dtrebbien authored and aduprat committed Dec 12, 2017
1 parent 9a06f40 commit f4b6276
Showing 1 changed file with 1 addition and 20 deletions.
Expand Up @@ -543,8 +543,8 @@ protected void internalStore(Mail mc) throws IOException, MessagingException {
PreparedStatement insertMessage = null;
try {
String insertMessageSQL = sqlQueries.getSqlString("insertMessageSQL", true);
int number_of_parameters = getNumberOfParameters(insertMessageSQL);
insertMessage = conn.prepareStatement(insertMessageSQL);
int number_of_parameters = insertMessage.getParameterMetaData().getParameterCount();
insertMessage.setString(1, mc.getName());
insertMessage.setString(2, repositoryName);
insertMessage.setString(3, mc.getState());
Expand Down Expand Up @@ -825,23 +825,4 @@ public int hashCode() {
}
return result;
}

/**
* This method calculates number of parameters in a prepared statement SQL
* String. It does so by counting the number of '?' in the string
*
* @param sqlstring
* to return parameter count for
* @return number of parameters
**/
private int getNumberOfParameters(String sqlstring) {
// it is alas a java 1.4 feature to be able to call
// getParameterMetaData which could provide us with the parameterCount
char[] chars = sqlstring.toCharArray();
int count = 0;
for (char aChar : chars) {
count += aChar == '?' ? 1 : 0;
}
return count;
}
}

0 comments on commit f4b6276

Please sign in to comment.