/** * Qoutes the passed {@code stringValue} if it's needed. * * @param stringValue * @param obj * @return */ private String quoteIfNeeded(String stringValue, Object obj) { if (stringValue == null) { return null; } /* * The following types do not get quoted: numeric, boolean * * It is tempting to use ParameterMetaData.getParameterType() for this * purpose as it would be safer. However, this method will fail with some * JDBC drivers. * * Oracle: Not supported until ojdbc7 which was released with Oracle 12c. * https://forums.oracle.com/thread/2584886 * * MySQL: The method call only works if service side prepared statements are * enabled. The URL parameter 'useServerPrepStmts=true' enables. */ if (Number.class.isAssignableFrom(obj.getClass()) || Boolean.class.isAssignableFrom(obj.getClass())) { return stringValue; } else { return "'" + escape(stringValue) + "'"; } }
/** * Qoutes the passed {@code stringValue} if it's needed. * * @param stringValue * @param obj * @return */ private String quoteIfNeeded(String stringValue, Object obj) { if (stringValue == null) { return null; } /* * The following types do not get quoted: numeric, boolean * * It is tempting to use ParameterMetaData.getParameterType() for this * purpose as it would be safer. However, this method will fail with some * JDBC drivers. * * Oracle: Not supported until ojdbc7 which was released with Oracle 12c. * https://forums.oracle.com/thread/2584886 * * MySQL: The method call only works if service side prepared statements are * enabled. The URL parameter 'useServerPrepStmts=true' enables. */ if (Number.class.isAssignableFrom(obj.getClass()) || Boolean.class.isAssignableFrom(obj.getClass())) { return stringValue; } else { return "'" + escape(stringValue) + "'"; } }