This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Selecting all columns but one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Selecting all columns but one" Watch "Selecting all columns but one" New topic
Author

Selecting all columns but one

Harsha Pherwani
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Hi,
I have about 30+ columns in my table. I want to select all columns but one column (which has to come from another table).
Do I have to specify each column name in the select clause or is there an easier and a better way of doing it?

All help appreciated.

Harsha
[ August 26, 2005: Message edited by: Harsha Pherwani ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
As far as I know, you can't create a query that specifies all-columns-except-for-one, or anything like that. So yes: in your case I believe you need to specify each of the columns you want.
Harsha Pherwani
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Thanks Stephen.

What I have done to get around this is:
In the select I get all columns i.e. * from the main table, and I select the column I want from another table and the alias name for this column is same as the column name I want to exclude.

When I execute the query in the database it gives me both the columns in the data output; but with JDBC while retrieving the values, when I invoke getString("<alias_name>") it gives me the value of the column from the second table. Thats what I need so my problem gets solved.
Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

Hi harsha

Why dont you use column index rather column name. like If you use rs.getString(1) and rs.getString(3) it will always give you the required column data rather the same you are getting now.


Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
 
Consider Paul's rocket mass heater.
 
subject: Selecting all columns but one