Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / July 2005

Tip: Looking for answers? Try searching our database.

jdbc arbitrary attributes

Thread view: 
shya - 23 Jul 2005 10:18 GMT
hi there!
I'm new to jdbc programming, and I can't find an answer for my problem.
Take for example this bunch of code:

protected void executeQuery( Connection con, String sqlStatement )
     throws Exception {

    try {
      Statement s = con.createStatement ( );
      ResultSet rs = s.executeQuery( sqlStatement );

      while ( rs.next ( ) ) {
        String id = ( rs.getObject ("id").toString() );
        String text = ( rs.getObject ("text").toString() );

        System.out.println ( "found record : " + id + " " + text );
      }

      rs.close ( );

    } catch ( SQLException e ) {
      System.out.println ( "Error executing sql statement" );
      throw ( e );
    }
}

well, in this query, it retrives the attributes "id" and "text" from the
result set. That's ok. But, how could I retrive _all_ the attributes in
a particular ResultSet without know them before?
For instance, my executeQuery method should be perform query like:

SELECT NAME, SURNAME
FROM TABLE1
WHERE etc...

or

SELECT *
FROM TABLE1
WHERe ...

can you help me?
thanks!

Signature

Shya

John Currier - 23 Jul 2005 22:00 GMT
The ResultSetMetaData returned by rs.getMetaData() will give you the
details you're looking for.  You'll also want to close your ResultSet
and Statement in a finally block.

John Currier
http://schemaspy.sourceforge.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.