java.sql.ResultSetMetaData.getColumnLabel和getColumnName的区别
2014-11-13 10:02
519 查看
如果将ResultSet的结果映射到HashMap中,要使用getColumnLabel,而不要用getColumnName,这样可提高程序的健壮性
理由:
getColumnName返回的是sql语句中field的原始名字。
getColumnLabel是field的SQL AS的值(Alias--别名)。
比如:select
a.name as name,
a.description as description,
b.description as relatedDescription
from a,b where ...
此时,getColumnName(3) == "description";而getColumnLabel(3) == "relatedDescription"。
API:
Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL
Parameters:
Get the designated column's name.
Parameters:
理由:
getColumnName返回的是sql语句中field的原始名字。
getColumnLabel是field的SQL AS的值(Alias--别名)。
比如:select
a.name as name,
a.description as description,
b.description as relatedDescription
from a,b where ...
此时,getColumnName(3) == "description";而getColumnLabel(3) == "relatedDescription"。
API:
getColumnLabel
String getColumnLabel(int column) throws SQLException
Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL
ASclause. If a SQL
ASis not specified, the value returned from
getColumnLabelwill be the same as the value returned by the
getColumnNamemethod.
Parameters:
column- the first column is 1, the second is 2, ...Returns:the suggested column titleThrows:
SQLException- if a database access error occurs
getColumnName
String getColumnName(int column) throws SQLException
Get the designated column's name.
Parameters:
column- the first column is 1, the second is 2, ...Returns:column nameThrows:
SQLException- if a database access error occurs
http://blog.sina.com.cn/s/blog_735ef3790100qmf3.html
相关文章推荐
- java.sql.ResultSetMetaData.getColumnLabel和getColumnName的区别
- Java ResultSetMetaData之getColumnName与getColumnLabel
- jdbc-mysql基础 ResultSetMetaData getColumnName getColumnLabel 得到列的名字和别名
- mysql别名取不出值(getColumnLabel和getColumnName的区别)
- ResultSetMetaData类的getColumnName和getColumnLabel的不同
- 使用mysql-connector-java.jar连接MySql时出现:Error while retrieving metadata for procedure columns: java.sql.SQLException: Parameter/Column name pattern can not be NULL or empty.
- 关于Java和SQL交互时的ResultSet.getString(“ Column ”)函数的自动补空格问题
- FAQ(52):java.sql.SQLException: Column Index out of range, 0 > 13. at com.mysql.jdbc.ResultSet.getInt
- 一个坑:java.sql.ResultSet.getInt==》the column value; if the value is SQL NULL, the value returned is 0
- java零碎要点---class()、getClass()、Class.forName()、getClassLoader()的区别和联系--又不详细的地方求补充
- sql server query to get the list of column name in a table
- java反射(1) 之class.forName(""), 类名.class, 对象.getClass()区别
- Java中反射机制和Class.forName、实例对象.class(属性)、实例对象getClass()的区别
- java零碎要点---class()、getClass()、Class.forName()、getClassLoader()的区别和联系--又不详细的地方求补充
- java getCanonicalName getSimpleName和getName的区别和用法
- Java中反射机制和Class.forName、实例对象.class(属性)、实例对象getClass()的区别
- MySQL JDBC驱动 - Class.forName和java.sql.DriverManager.registerDriver (new Driver())的区别
- java.sql.SQLException: Incorrect string value: '\xE6\x88\x91\xE7\x9A\x84...' for column 'groupName'
- Java中的getName(), .class 和forName()的区别
- Java中反射机制和Class.forName、实例对象.class(属性)、实例对象getClass()的区别