This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes ResultSetMetaData, Alias Columnnames Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSetMetaData, Alias Columnnames" Watch "ResultSetMetaData, Alias Columnnames" New topic
Author

ResultSetMetaData, Alias Columnnames

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hello folks
I have an application which utilizes a query to take data from a database table & write to an XML file and vice-versa. I have a problem in solving the alias name in queries.
e.g Select EmpID as EmployeeID from Employee.. Where EmpID is the original Column name in Table, and when i have the result set metadata, i am not able to get the Original Column name EmpID? is there any other way to get it? or it is b'cos of the JDBC driver?
i have tried using:
rsmd.getColumnLabel(int position) ==> gives EmployeeID rsmd.getColumnName(int position) ==> gives EmployeeID and not EmpID
Kindly help.
Thanks
sathish
Daniel Dunleavy
Ranch Hand

Joined: Mar 13, 2001
Posts: 276
When you alias the column, your giving it a new name to the result set.
You can use the metadata to get to the actual column name
ResultSetMetaData rsmd1 = rs.getMetaData();
String colname = rsmd1.getColumnName(i);
The i is the index for the column
Good Luck
Dan
 
Have you checked out Aspose?
 
subject: ResultSetMetaData, Alias Columnnames
 
It's not a secret anymore!