Spring RowMapper callback Interface and QUERYFOR series summary

Source: Internet
Author: User

public void Queryfor () throws Exception {

StringBuilder sql=new StringBuilder ()

. Append ("Select Pid,pname,psex,pnationality,phobby,pdescription from where pid=?")

;

Object args[]={12};

Person p= () this.getjdbctemplate (). queryForObject (

Sql.tostring (),

Args

New RowMapper () {

Public Object Maprow (ResultSet rs, int arg1) throws SQLException {

Person P=new person ();

P.setpid (Rs.getint (1));

P.setpname (rs.getstring (2));

P.setpsex (Rs.getstring (3));

P.setpnationality (Rs.getstring (4));

P.setphobby (Rs.getstring (5));

P.setpdescription (rs.getstring (6));

return p;

}

}

);

System.out.println (P.getpid ());

System.out.println (P.getpname ());

}

Note: Spring's JDBC template provides a Queryfor series of methods:

queryForList (String sql,object args[],class ElementType)

Query for question mark in Object Args[]:sql statement

Class ElementType can check a column of multiple records the type of this column can be defined by itself as: String.class

queryForObject (String sql,class requiredtype) can query only one column of a single record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.