ResultSetMetaData Hello World!

Get information about the table you are playing with using ResultSetMetaData.

ResultSetMetaDataHelloWorld.java
import java.sql.*;
 
public class ResultSetMetaDataHelloWorld {
 
    private final static String url = "jdbc:h2:~/sampleh2db;TRACE_LEVEL_FILE=0;AUTO_SERVER=TRUE";
    private final static String user = "test";
    private final static String password = "test";
 
    public static void main(String[] args) throws SQLException {
        final Connection connection = DriverManager.getConnection(url, user, password);
        final Statement statement = connection.createStatement();
 
        final ResultSet resultSet = statement.executeQuery("SELECT * FROM EMPLOYEE");
        final ResultSetMetaData metaData = resultSet.getMetaData();
 
        final int columnCount = metaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            System.out.println(metaData.getColumnLabel(i));
        }
 
        statement.close();
        resultSet.close();
        connection.close();
    }
}

Sample Output
ID
ADDRESS
CITY
FIRSTNAME
LASTNAME
EMPLOYEE_LEDGER_ID