Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get maximum column data legth in existing record

shabarMay 17 2012 — edited May 18 2012
Hi All


I have requirement to get maximum column data length for existing record set.

As a example I got below record set and need to get maximum length of each column data length*

Basically this is because to align the data by padding when writing to the text file. So if I get the max data length in the column, could replace value 15 (i.e. %-15s)
ResultSet rs = st.executeQuery(SQuery); 

while (rs.next()) {
                                    String col1 = rs.getString(output1);
                                    String col2 = rs.getString(output2);
                                    String col3 = rs.getString(output3);
                                    
                                    
                                                                       
                                    data.add(col1.format("%-15s", col1) + "\t" + col2.format("%-15s", col2) + "\t\t" + col3);
                                    
                            }
Or if any alternative.......


cheers
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2012
Added on May 17 2012
4 comments
1,515 views