how can i get the column name in a database?

jebit 2003-12-10 04:59:54
when i excute a query like "select A as B from table;",
i found the resultsemetadata.getColumnName(index) could only return B.
how can i get A?

thanks
...全文
48 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ddbean 2003-12-11
  • 打赏
  • 举报
回复
I have another suggestion:
U can use "select namea as nameb from table;" to get a resultset, but when you want to get your original column name, try to get it in the table of database, do not get it in the resultset.

Good Luck!!!
jebit 2003-12-10
  • 打赏
  • 举报
回复
thanks a lot,ddbean :)

One of my class needs to know both the alias and the original column name, though the "select namea from table;" and the "select namea as nameb from table;" will generate the some resultset.

i searched many forums and found no solution.
it seems that it's impossible to obtain the original column name.

:(
i'm considering making some changes in my design.
ddbean 2003-12-10
  • 打赏
  • 举报
回复
'namea as nameb' is just give a alias to namea, the nameb have the content which namea had, If you use "select namea from table;" ,you can also have the same resultset,

I just not quit sure why U use 'namea as nameb' here, and then why you want to get the ColumnName as namea,

if the nameb don't have special meaning here ,I suggest you use "select namea from table;"
jebit 2003-12-10
  • 打赏
  • 举报
回复
thanks for your help.


here's my code;

Query q = new String("select namea as nameb from table;");
ResultSet resultSet = statement.excuteQuery(q);
ResultSetMetaData rsmd = resultSet.getMeta();
System.out.println( rsmd.getColumnName(1) );


the output is:

nameb


what i want to obtain is the original column name "namea".

ddbean 2003-12-10
  • 打赏
  • 举报
回复
why do U execute this operation: 'A as B'?
"select A as B from table" can get A

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧