项目中需要获得返回结果集的列别名,但是找不到方法。请大家帮忙。
比如:SELECT column_1 as c1 ,column_2 as c2 from table
connection = DriverManager.getConnection(URL, userName, password);
//这个方法能获得数据库是否支持别名
DatabaseMetaData dbMeta = connection.getMetaData();
System.out.println(dbMeta.supportsColumnAliasing());
preparedstatement = connection.prepareStatement(s1);
ResultSet resultset = preparedstatement.executeQuery();
ResultSetMetaData resultsetmetadata = resultset.getMetaData();
//[color=red]这里只能获取到字段的实际名称 column_1 和 column_2[/color]
//[color=red]但是无法获得别名 c1 和 c2[/color]
resultsetmetadata.getColumnName(1);
resultsetmetadata.getColumnName(2);
请问我想[color=red]要获取别名 c1 和 c2 [/color]应当怎么操作呢?JavaAPI中有对应的方法吗?
/**
* Gets the designated column's suggested title for use in printouts and
* displays. The suggested title is usually specified by the SQL AS
* clause. If a SQL AS
is not specified, the value returned from
* getColumnLabel
will be the same as the value returned by the
* getColumnName
method.
*
* @param column the first column is 1, the second is 2, ...
* @return the suggested column title
* @exception SQLException if a database access error occurs
*/
String getColumnLabel(int column) throws SQLException;
ResultSetMetaData.getColumnLabel(int column) throws SQLException;