import java.awt.*; import java.awt.event.*; import java.util.*; import java.sql.*; public class ColumnExample extends Frame { public ColumnExample () { super("ColumnExample"); this.setSize(300, 300); this.setVisible( true ); // Add the TextArea Object TextArea text = new TextArea(25, 80); this.add("center", text); //Add ActionListener para Fechar Aplicacao this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); try { String driverName = "sun.jdbc.odbc.JdbcOdbcDriver"; Driver driver = (Driver)Class.forName(driverName).newInstance(); Properties p = new Properties(); p.put("user", "p8cp1"); p.put("password", "ismael"); String dbURL = "jdbc:odbc:fiaa"; Connection connection = driver.connect(dbURL, p); System.out.println("--- Conection established ---"); String sql = "select * from Pessoa"; Statement sqlStatement = connection.createStatement(); ResultSet records = sqlStatement.executeQuery(sql); // Get the meta data object ResultSetMetaData metaData = records.getMetaData(); // Call the displayColumns() method displayColumns(metaData, text); } catch (SQLException e) {} catch (Exception e) {} } private void displayColumns (ResultSetMetaData metaData, TextArea text) { String s = ""; try { // Get the number of columns in result set int count = metaData.getColumnCount(); // Cycle through columns and get name of each one for (int i = 1; i <= count; i++) { s += metaData.getColumnName(i); } } catch (SQLException e) {} // Put the text string in the text area text.setText(s); } public static void main (String args[]) { ColumnExample app = new ColumnExample(); } }