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
BrianMc1958Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

0
zzynxSoftware engineerCommented:
0
bloodredsunCommented:
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.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrianMc1958Author Commented:
You folks are amazing.  Thanks!
--BrianMc1958
0
zzynxSoftware engineerCommented:
No split? :(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.