首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

求JdbcTemplate().queryForList()方法各参数的详解,该如何处理

2012-03-25 
求JdbcTemplate().queryForList()方法各参数的详解求JdbcTemplate.queryForList()方法各不同参数的详解[解

求JdbcTemplate().queryForList()方法各参数的详解
求JdbcTemplate.queryForList()方法各不同参数的详解

[解决办法]

HTML code
queryForList 
public List queryForList(String sql,
            Object[] args,
            int[] argTypes,
            Class elementType)
        throws DataAccessExceptionDescription copied from interface: JdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.


Specified by:
queryForList in interface JdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
argTypes - SQL types of the arguments (constants from java.sql.Types)
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
JdbcOperations.queryForList(String, Class), SingleColumnRowMapper

--------------------------------------------

queryForList
public List queryForList(String sql,
            Object[] args,
            Class elementType)
        throws DataAccessExceptionDescription copied from interface: JdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.


Specified by:
queryForList in interface JdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
elementType - the required type of element in the result list (for example, Integer.class)
Returns:
a List of objects that match the specified element type
Throws:
DataAccessException - if the query fails
See Also:
JdbcOperations.queryForList(String, Class), SingleColumnRowMapper

--------------------------------------------

queryForList
public List queryForList(String sql,
            Object[] args,
            int[] argTypes)
        throws DataAccessExceptionDescription copied from interface: JdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Thus Each element in the list will be of the form returned by this interface's queryForMap() methods.


Specified by:
queryForList in interface JdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
argTypes - SQL types of the arguments (constants from java.sql.Types)
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
JdbcOperations.queryForList(String), Types



--------------------------------------------

queryForList
public List queryForList(String sql,
            Object[] args)
        throws DataAccessExceptionDescription copied from interface: JdbcOperations
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.
The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's queryForMap() methods.


Specified by:
queryForList in interface JdbcOperations
Parameters:
sql - SQL query to execute
args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
a List that contains a Map per row
Throws:
DataAccessException - if the query fails
See Also:
JdbcOperations.queryForList(String)


[解决办法]
除了返回单值的查询方法,JdbcTemplate还提供了一组返回List结果 的方法。List中的每一项对应查询返回结果中的一行。其中最简单的是queryForList方法, 该方法将返回一个List,该List中的每一条 记录是一个Map对象,对应应数据库中某一行;而该Map 中的每一项对应该数据库行中的某一列值。下面的代码片断接着上面的例子演示了如何用该方法返回表中 所有记录: 

public List getList() {
jt = new JdbcTemplate(dataSource);
List rows = jt.queryForList("select * from mytable");
return rows;
}

[解决办法]
Java code
public List queryForList(String sql,         // 查询用的sql句                         Object[] args,      // sql句中的预处理参数                         int[] argTypes,     // 参数的类型,取自于java.sql.Types                         Class elementType)  // 在结果列表中的参数类型,例如Integer.Class
[解决办法]
public List queryForList(String sql, //sql 语句
Object[] args, //sql中参数,用数组对应
Class elementType) //对应Bean包装结果

[解决办法]
#7楼 的你也太自大了吧
我就喜欢这么问问题
现在我纯靠技术年薪15万

当然了你也可以说我机缘巧合走了运
但是你不会也怀疑肯于给出这样待遇的公司的人事和考官的眼光和择人标准吧

技术多了去了 每样都去细学你学的完吗?
我更想明白的说:你 是 傻 B
[解决办法]
String sql, // 查询用的sql句
Object[] args, // sql句中的参数
int[] argTypes, // sql句中的参数的数据类型(java类型)
Class elementType) // list装载结果的元数据类型

热点排行