Forums Register Login

Trying to make Java method to get the length of a column

+Pie Number of slices to send: Send
Here's what I've tried. The 'rs' variable references a ResultSet object, and the 'meta' variable references a DatabaseMetaData object.



The column I'm trying to access contains 3 rows with the values being "Joel", "Hannah", and "Kevin. Since I'm trying to get the size of the column, my desired return value would be 3, but it's returning 25.
1
+Pie Number of slices to send: Send
That's because the size of a column is its length. It has nothing whatsoever to do with the number of rows.

In fact, the number of rows has nothing at all to do with a specific column but the table as a whole.

If you want to get the number of rows, you'd do that with a SELECT COUNT(*) statement.
+Pie Number of slices to send: Send
If you want to exclude records with NULL values you should replace that COUNT(*) with COUNT(name_of_column).
+Pie Number of slices to send: Send
Thanks for the help; it now returns 3. My new method:

Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 898 times.
Similar Threads
ORM Vs JDBC
Array index out of bounds exception
How to find the column names..???
DatabaseMetaData.getExportedKeys() returns empty ResultSet
SQL exception
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 20:29:03.