Question

I want to know how to get the column count of resulting output in MySQL.

I searched this site for the same question but i'm little different.

I want to get the column count of resulting output not of the table.

I want to know how many columns are there in the resulting output when a query is passed.

Thanxx in advance!

Was it helpful?

Solution

ResultSetMetaData metadata = resultSet.getMetaData();
int columnCount = metadata.getColumnCount();

OTHER TIPS

Use ResultSetMetaData#getColumnCount() method to get the count in java

ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();

you don´t need a ResultSetMetaData variable, just try this code:

int columCount = rs.getMetaData().getColumnCount();

the rs is a Resulset.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top