我面临问题,找出特定的列名称。我正在使用 SQL Server 2005 并在 struts 2 框架中编码。
这是需要做的:
我想找出特定行中具有特定值的列名。
例如:
在员工表的一行中,如果特定列的值为“true”,我想知道列名。
我知道在 SQL Server 中我们可以使用此查询访问表的所有列名:
select column_name from information_schema.columns where table_name = 'table's name'
但我无法实现我的目的。
我想我已经清楚地定义了我的问题,如果我错过了什么,请告诉我。
谢谢!!
I am facing problem, finding out specific column names. I am using SQL Server 2005 and am coding in struts 2 framework.
Here is what needs to be done:
I want to find out the column names which have a particular value in a particular row.
For example:
In a row in employee table, if the value of a particular column is "true", I want to know the column name.
I know in SQL server we can access all the column names of a table using this query:
select column_name from information_schema.columns where table_name = 'table's name'
but I am not able to fulfill my purpose.
I guess I have defined my issue clearly, if there is anything that I missed out please tell.
Thanks!!
发布评论
评论(1)
我假设您没有使用 ORM,而是使用 JDBC,但遗憾的是您没有说明如何从数据库获取数据。
您需要使用
ResultSetMetaData
如果您正在使用 JDBC。 您可以从中通过索引获取列的名称。I'll assume you're not using an ORM, and that you're using JDBC, although unfortunately you don't say how you're getting data from the database.
You need to use
ResultSetMetaData
if you're using JDBC. from which you can get the name of a column by its index.