Обсуждение: ParameterMetaData getPrecision() always zero?

Поиск
Список
Период
Сортировка

ParameterMetaData getPrecision() always zero?

От
Simon Temple
Дата:
Driver: postgresql-8.4-701.jdbc4
Server: 8.4
OS: Mac OSX

<snip>
    ParameterMetaData m = stat.getParameterMetaData(  );

    if ( null != m ) {

        int colWidth = m.getPrecision( parameterIndex );

        // colWidth == 0 means 'not applicable'
        if ( colWidth > 0 ) {
<snip>

I have the same behaviour with many different tables.  

For varchar columns I would expect to get the maximum column width.  So 8 for a varchar(8).

I always get zero as a result.

I get non zero values from H2 and Derby drivers.

Is this a bug or have I missed something?

TIA

Simon Temple


Re: ParameterMetaData getPrecision() always zero?

От
Kris Jurka
Дата:

On Thu, 28 Jan 2010, Simon Temple wrote:

>     ParameterMetaData m = stat.getParameterMetaData(  );
>     int colWidth = m.getPrecision( parameterIndex );
>
> For varchar columns I would expect to get the maximum column width.  So 8
> for a varchar(8).
>
> I always get zero as a result.
>

This is the best the JDBC driver can do.  When preparing a statement, the
server only returns the datatypes, not additional details about the size.
This is because the parameters do not always match up with a table column.
Consider "WHERE replace(col, 'a', 'bb') = ?"  you won't be able to tell
the parameter size from that.

Kris Jurka