Link to home
Start Free TrialLog in
Avatar of BrianMc1958
BrianMc1958

asked on

What is best way to get metadata?

Dear Experts,

To get metadata for a particular table within Java, I have been doing this:

    String s = "SELECT TOP 1 * FROM " + table_full_name; // just to get metadata
    try
    {
      Statement st = conn.createStatement();
      ResultSet rs = st.executeQuery(s);
      ResultSetMetaData rsmd = rs.getMetaData();
      int maxcol = rsmd.getColumnCount();
      for (int col = 1; col <= maxcol; col++)
      {
        // process metadata
      }
    }

Is there a simpler, more direct method?  It seems awkward to have to select a row first...

Thanks,
BrianMc1958
Avatar of zzynx
zzynx
Flag of Belgium image

>> It seems awkward to have to select a row first...
Nevertheless that's the way to go I think.
Moreover, you don't call rs.next(), so I think you don't really select

For simple JDBC like above, not that I know of but I'd be happy for someone else to correct me...

You could investigate Connection.getMetaData() but that returns a DatabaseMetaData object.
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrianMc1958
BrianMc1958

ASKER

You folks are amazing.  Thanks!
--BrianMc1958
No split? :(