Friday, November 16, 2001

Java JDBC Metadata Holds Query Column Names

  private Connection mAccess;
  private Statement mStatement;
  private ResultSet mResultSet;
  private ResultSetMetaData mResultSetMetaData;

  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  mAccess = DriverManager.getConnection("jdbc:odbc:pma_boeing");

  mStatement = mAccess.createStatement();
  ResultSet mResultSet = mStatement.executeQuery("Select top 10 * from boeing");

  mResultSetMetaData = mResultSet.getMetaData();
  int TotalColumn = mResultSetMetaData.getColumnCount();

  for (int j = 1; j <= TotalColumn; j++) {
    System.out.println("[" + j + "] " + mResultSetMetaData.getColumnName(j));
  }
Post a Comment