Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared Statement that specifies field aliases

 
Debbie Argulkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there a way to write a PreparedStatement that will let you assign the data values to an alias?
If the datacolumn in the database is called Name, can you map it to the alias "CustomerName", through the prepared statement? Is there any other way to do this?
Thanks,
-Deb
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deb,
Most of the databases that I have worked with allow you to define column aliases in the SQL query, for example:

Note: I think that this may be part of standard SQL (but I'm not sure).
However, if you want to change the column name _after_ you have created your "PreparedStatement" object, I don't think this is possible.
Hope this has helped you.
Good Luck,
Avi.
 
Veena Rani
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the column aliases in both Statement and prepared statements.

Select name CustomerName from Customer
here CustomerName is alias name for column name.
a sql query like this can be used in both statement or prepared statement
Veena
 
Debbie Argulkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Veena,
Thanks. I will try that out.
-Deb
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic