Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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
      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...

1 Solution
zzynxSoftware engineerCommented:
>> 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

zzynxSoftware engineerCommented:
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

From the Javadoc of PreparedStatement :

Retrieves a ResultSetMetaData object that contains information about the columns of the ResultSet object that will be returned when this PreparedStatement object is executed.
Because a PreparedStatement object is precompiled, it is possible to know about the ResultSet object that it will return without having to execute it. Consequently, it is possible to invoke the method getMetaData on a PreparedStatement object rather than waiting to execute it and then invoking the ResultSet.getMetaData method on the ResultSet object that is returned.

BrianMc1958Author Commented:
You folks are amazing.  Thanks!
zzynxSoftware engineerCommented:
No split? :(

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now