求JdbcTemplate.queryForList()方法各不同参数的详解
解决方案 »
- J2EE项目打包 发布
- 需求要为后台操作做权限限制,如何实现,与代码无关?
- 大虾们帮帮忙 解决解决这个问题。---严重: action: null
- struts2 <s:select>标签我想实现不能选择,但是能把数据提交到服务器,怎么实现?急,在线等
- 50分问关于cache机制简单问题
- 紧急求助,大家帮我看看这是个什么错误
- 怎么用apache-ant构建j2ee
- relation的问题?
- j2ee deploytool:Could not connect to localhost!怎么会有这种错误?!
- 各位大侠救救我吧,这个问题解决不了就没法活了
- 关于Java 对数据库查询去重复的问题。
- 如何知道哪些jar是必须的,如何解决jar的冲突问题
好象参数很少吧?
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)
jt = new JdbcTemplate(dataSource);
List rows = jt.queryForList("select * from mytable");
return rows;
}
public List queryForList(String sql, // 查询用的sql句
Object[] args, // sql句中的预处理参数
int[] argTypes, // 参数的类型,取自于java.sql.Types
Class elementType) // 在结果列表中的参数类型,例如Integer.Class
多个构造方法,可灵活运用。
Object[] args, //sql中参数,用数组对应
Class elementType) //对应Bean包装结果
Object[] args, // sql句中的参数
int[] argTypes, // sql句中的参数的数据类型(java类型)
Class elementType) // list装载结果的元数据类型
该List中的每一条 记录是一个Map对