[ 
https://issues.apache.org/jira/browse/DBUTILS-153?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jarrad Waterloo updated DBUTILS-153:
------------------------------------
    Description: 
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.

 

  was:
Revise the following method

void AbstractQueryRunner.fillStatement(final PreparedStatement stmt, final 
ParameterMetaData pmd, final Object... params)

 

to either auto pad 

 

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

 

 


> 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