Database column size using JDBC getMetdata

Database
Enthusiast

Database column size using JDBC getMetdata

Hi,

  Our application lets admins access Teradata tables through frontend views. Certains columns are editable. We are trying to limits users to enter only a certain length of value given what the database column size has been defined as. 

We were hoping the following Java JDBC call will help us out in figuring the max size per column, but its not helping.

This is the code snippet that we were hoping that some one can help us out with:

dbColumnName = rs.getMetaData().getColumnName(colIndx);

                                        columnInfo = new DataTableColumnMetaData(colIndx-1,

                                                                                                        dbColumnName, 

                                                                                                                rs.getMetaData().getColumnLabel(colIndx), 

                                                                                                                rs.getMetaData().getColumnType(colIndx),

                                                                                                                rs.getMetaData().getPrecision(colIndx),

                                                                                                                rs.getMetaData().getScale(colIndx), 

                                                                                                                rs.getMetaData().getColumnDisplaySize(colIndx),

                                                                                                                rs.getMetaData().isNullable(colIndx),

                                                                                                                false,/* NOT VISIBLE */

                                                                                                                false);

The JDBC driver version are: Implementation-Version: 14.10.00.17

1 REPLY
Teradata Employee

Re: Database column size using JDBC getMetdata

The ResultSetMetaData.getColumnDisplaySize method returns the maximum number of characters needed to display the designated column's values in character form. It should provide a fairly good approximation for your need.