queryForMap(String sql)
引數說明:public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //載入組態檔 Dao dao = (Dao)context.getBean("dao"); //建立Dao JdbcTemplate jtm = dao.getJdbcTemplate(); String sql = "select*from tb_user where id=1"; //建立一條SQL語句 Map map = jtm.queryForMap(sql); System.out.println(map); }
queryForMap(String sql,Object[] args)
引數說明:public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("cfg/XMLConfig.xml"); //載入組態檔 Dao dao = (Dao)context.getBean("dao"); //建立Dao JdbcTemplate jtm = dao.getJdbcTemplate(); String sql = "select*from tb_user where age=?and sex=?limit 1"; //建立一條SQL語句 Object[] sqlArgs = {27,"男"}; Map map = jtm.queryForMap(sql,sqlArgs); System.out.println(map); }