?
Solved

What is best way to get metadata?

Posted on 2005-03-23
6
Medium Priority
?
215 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:BrianMc1958
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 13611806
>> 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
 
LVL 37

Expert Comment

by:zzynx
ID: 13611813
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13611821
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 15

Accepted Solution

by:
aozarov earned 200 total points
ID: 13611909
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
 

Author Comment

by:BrianMc1958
ID: 13612181
You folks are amazing.  Thanks!
--BrianMc1958
0
 
LVL 37

Expert Comment

by:zzynx
ID: 13612349
No split? :(
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question