[
https://issues.apache.org/jira/browse/DBUTILS-153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938618#comment-17938618
]
Gary D. Gregory commented on DBUTILS-153:
-----------------------------------------
Something like this should not be done by default if at all.
What level is your requirement coming from?
The application, the JDBC driver, or the database?
Are you saying you want the database to store values like "NAME. " instead
of "NAME"?
> AutoPad PreparedStatement parameters
> ------------------------------------
>
> Key: DBUTILS-153
> URL: https://issues.apache.org/jira/browse/DBUTILS-153
> Project: Commons DbUtils
> Issue Type: Bug
> Reporter: Jarrad Waterloo
> Priority: Major
>
> Revise the following method
> void AbstractQueryRunner.fillStatement(final PreparedStatement stmt, final
> ParameterMetaData pmd, final Object... params)
>
> to either auto pad PreparedStatement parameters when the types are CHAR and
> NCHAR OR provide the ability for the AbstractQueryRunner to be configured to
> do such.
>
> He is the code which is technically being asked for.
>
> if(pmd.getParameterType(ordinal) == java.sql.Types.CHAR ||
> pmd.getParameterType(ordinal) == java.sql.Types.NCHAR)
> {
> final String paddedValue = StringUtils.rightPad(value,
> pmd.getPrecision(ordinal), ' ');
> ps.setObject(1, paddedValue);
>
> This is a reasonable thing to do at this level as database drivers may not be
> doing it at their level such as Oracle's database drivers.
>
> Padding is the default behavior of most SQL databases including Oracle,
> MySQL, Microsoft SQL Server and many others.
>
> The problem is when doing a SQL query with an unpadded value the SQL works
> but the same query and value on a prepared statement fails to return results.
> The ParameterMetaData already has the parameter size, it just needs to be
> used.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)