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

解决方案 »

  1.   

    JdbcTemplate.queryForList(sql)
    好象参数很少吧?
      

  2.   

    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)
      

  3.   

    除了返回单值的查询方法,JdbcTemplate还提供了一组返回List结果 的方法。List中的每一项对应查询返回结果中的一行。其中最简单的是queryForList方法, 该方法将返回一个List,该List中的每一条 记录是一个Map对象,对应应数据库中某一行;而该Map 中的每一项对应该数据库行中的某一列值。下面的代码片断接着上面的例子演示了如何用该方法返回表中 所有记录: public List getList() {
        jt = new JdbcTemplate(dataSource);
        List rows = jt.queryForList("select * from mytable");
        return rows;
    }
      

  4.   


    public List queryForList(String sql,         // 查询用的sql句
                             Object[] args,      // sql句中的预处理参数
                             int[] argTypes,     // 参数的类型,取自于java.sql.Types
                             Class elementType)  // 在结果列表中的参数类型,例如Integer.Class
    多个构造方法,可灵活运用。
      

  5.   

    public List queryForList(String sql, //sql 语句
                             Object[] args, //sql中参数,用数组对应
                             Class elementType) //对应Bean包装结果
      

  6.   

    String sql,         // 查询用的sql句
                             Object[] args,      // sql句中的参数
                             int[] argTypes,     // sql句中的参数的数据类型(java类型)
                             Class elementType)  // list装载结果的元数据类型
      

  7.   

    有java高手的可以留个QQ号 交流一下我是刚毕业的java菜鸟 希望大家多多关照^……
      

  8.   

    一看就知道没有看过spring文档和源代码的人,你觉得问这种问题的人一个月能够学多少知识。我觉得你不该做软件开发。换行吧。还没有入门。我最讨厌说这样话的人,以为自己很牛B似的,我敢保证,能说出这话的人,肯定学的不咋得,技术么,就是互相交流,互相学习的过程,每个人不肯定把全部的知识都学到。
      

  9.   


    该List中的每一条 记录是一个Map对
      

  10.   

    虽然是老贴子,但是顶啊 学习中,7楼是S B ,最鄙视这种人 不回答问题就算了,还JJYY的惹人骂。想学凤姐搞反角出名啊?