BF [ 2030233 ] Remove duplicate code from DB class
+ *
FR [ 2107062 ] Add more DB.getKeyNamePairs methods
*/
public final class DB
{
@@ -792,7 +794,7 @@ public final class DB
* @param stmt statements
* @param params parameters array; if null or empty array, no parameters are set
*/
- private static void setParameters(PreparedStatement stmt, Object[] params)
+ public static void setParameters(PreparedStatement stmt, Object[] params)
throws SQLException
{
if (params == null || params.length == 0) {
@@ -805,6 +807,25 @@ public final class DB
}
}
+ /**
+ * Set parameters for given statement
+ * @param stmt statements
+ * @param params parameters list; if null or empty list, no parameters are set
+ */
+ public static void setParameters(PreparedStatement stmt, List> params)
+ throws SQLException
+ {
+ if (params == null || params.size() == 0)
+ {
+ return;
+ }
+ for (int i = 0; i < params.size(); i++)
+ {
+ setParameter(stmt, i+1, params.get(i));
+ }
+ }
+
+
/**
* Set PreparedStatement's parameter.
* Similar with calling pstmt.setObject(index, param)
@@ -1328,24 +1349,54 @@ public final class DB
}
/**
- * Get Array of Key Name Pairs
- * @param sql select with id / name as first / second column
- * @param optional if true (-1,"") is added
- * @return array of key name pairs
+ * Get Array of Key Name Pairs
+ * @param sql select with id / name as first / second column
+ * @param optional if true (-1,"") is added
+ * @return array of {@link KeyNamePair}
+ * @see #getKeyNamePairs(String, boolean, Object...)
*/
public static KeyNamePair[] getKeyNamePairs(String sql, boolean optional)
+ {
+ return getKeyNamePairs(sql, optional, (Object[])null);
+ }
+
+ /**
+ * Get Array of Key Name Pairs
+ * @param sql select with id / name as first / second column
+ * @param optional if true (-1,"") is added
+ * @param params query parameters
+ * @return array of {@link KeyNamePair}
+ * @see #getKeyNamePairs(String, boolean, Object...)
+ */
+ public static KeyNamePair[] getKeyNamePairs(String sql, boolean optional, Collection