Shivam Arora
Shivam Arora

Reputation: 107

Getting column count of the MySQL output with Java

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!

Upvotes: 1

Views: 3426

Answers (3)

Adrian
Adrian

Reputation: 1

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

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

the rs is a Resulset.

Upvotes: 0

Bhavik Shah
Bhavik Shah

Reputation: 5183

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

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

Upvotes: 1

mauretto
mauretto

Reputation: 3212

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

Upvotes: 1

Related Questions