This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Select Particular Column values in sql without know the column name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Select Particular Column values in sql without know the column name" Watch "Select Particular Column values in sql without know the column name" New topic
Author

Select Particular Column values in sql without know the column name

prakasham selamban
Greenhorn

Joined: Apr 16, 2009
Posts: 15
I want to get particular column values in sql table.For example if table has 10 columns i want to select the values of 4 to 10 column values. Here i dont know the column names because all columns are generated at a run time. i need help as soon as possible. I have searched in lot but i could not find the sql query.


prakasham
Charbel Keyrouz
Ranch Hand

Joined: Jun 10, 2005
Posts: 46
After you execute your query and in the rs.next loop do the following:

Instead of calling the fieldname you can get the value by index of the column.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

There also should be a way to query for the column names in your code. It would depend on what api you are using to connect/run against the DB.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
prakasham selamban
Greenhorn

Joined: Apr 16, 2009
Posts: 15
Thanks for your reply.

I want the sql query to select records
Charbel Keyrouz
Ranch Hand

Joined: Jun 10, 2005
Posts: 46
If you want the column names you can get them as follows:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Select Particular Column values in sql without know the column name
 
Similar Threads
Getting sql error [Microsoft ][odbc microsoft access driver]numeric index out of range
Problem with preapred Statement
call resultset in join query
h:dataTable creating dynamically
Getting table name for column