Spring JdbcTemplate Usage Summary

Source: Internet
Author: User

1. Querying object

     Public Classify Queryclassifbyid (int  ID) {        String sql= "SELECT * from T_classify where id=?" ;         New object[] {ID};         = Jdbctemplate.queryforobject (sql, args, parameterizedbeanpropertyrowmapper.newinstance (classify.  Class));         return classify;    }

2. Query List

     Public List<classify> Getallmenu () {        String sql= "SELECT * from t_classify";        List<Classify> list = jdbctemplate.query (sql, Parameterizedbeanpropertyrowmapper.newinstance (classify.  Class));         return list;    }

3. Number of query records

     Public int GetCount () {        String sql= "SELECT count (*) from t_classify";         return jdbctemplate.queryforint (SQL);    }

4. Get self-growth primary key

     Public intInsertFinalNews News) {        FinalString sql = "INSERT into T_news (title, content)" + "VALUES (?,?)"; Keyholder Keyholder=NewgeneratedKeyHolder (); Jdbctemplate.update (NewPreparedStatementCreator () {@Override PublicPreparedStatement createpreparedstatement (Connection conn)throwsSQLException {preparedstatement ps=conn.preparestatement (SQL); Ps.setstring (1, News.gettitle ()); Ps.setstring (2, News.getcontent ());returnPS;        }},keyholder); returnKeyholder.getkey (). Intvalue (); }

Spring JdbcTemplate Usage Summary

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.