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 summary of the methods of the Queryfor series:
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