Here you can find the source of getFieldNames(ResultSet rs)
Parameter | Description |
---|---|
rs | ResultSet to be examinated |
Parameter | Description |
---|---|
SQLException | an exception |
private static String[] getFieldNames(ResultSet rs) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { /**//w ww.j a va2s . c om * Return field names * @param rs ResultSet to be examinated * @return array containing field names * @throws SQLException */ private static String[] getFieldNames(ResultSet rs) throws SQLException { if (rs == null) return null; // Return db information based on result set ResultSetMetaData metaData = rs.getMetaData(); // Return filed number of table specified in SQL query int col_num = metaData.getColumnCount(); String[] col_names = new String[col_num]; // Creates array with field names for (int i = 0; i < col_num; i++) col_names[i] = metaData.getColumnName(i + 1); return col_names; } }