[ 
https://issues.apache.org/jira/browse/DBUTILS-153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938985#comment-17938985
 ] 

Gary D. Gregory commented on DBUTILS-153:
-----------------------------------------

Hello [~jordan76] 

I still don't see how this is not a JDBC driver problem. Do you get an 
exception? How does the problem surface in your app?

TY.

> 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)

Reply via email to