Spring queryforobject method: the result of the query is returned as an object type

queryForObject(String sql,Class requiredType)

Example

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 name from tb_user limit 1";  //创建一条sql语句
  String name = (String)jtm.queryForObject(sql,String.class);
  System.out.println(name);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>