14.JdbcUtils Frame

Source: Internet
Author: User

1. Writing your own jdbcutils framework

2. Using the Dbutils framework

1. The jdbcutils frame you wrote in the video is almost the dbutils frame.

2. Use

Complete curd using the Dbutils framework, and batch processing

Complete processing of result sets using dbutils of various types of processors

1 @Test2      Public voidFind ()throwsSQLException {3Queryrunner QR =NewQueryrunner (Jdbcutils.getdatasource ());4String sql = "SELECT * from user where id=?";5Object params[] = {2 };6User user = (user) qr.query (SQL, params,NewBeanhandler (User.class));7 System.out.println (User.getbirthday ());8     }9 Ten @Test One      Public voidGetAll ()throwsSQLException { AQueryrunner QR =NewQueryrunner (Jdbcutils.getdatasource ()); -String sql = "SELECT * from User"; -List List = (list) qr.query (SQL,NewBeanlisthandler (User.class)); the System.out.println (List.size ()); -}

1. Requires a database connection pool (new out in the Utils class)

2. Determine if you need to write parameters (two cases 1.sql statements have parameters to specify 2. Some processors need to specify parameters)

Arrayhandler (encapsulates the first row of data in the result set into an array)

Arraylisthandler (place each row of data in the result set in an array, placing the arrays in a list)

Beanhandler (encapsulates the first row of data in a result set into a bean)

Beanlisthandler (encapsulates each row of data in the result set into a bean, placing the beans in a list)

Columnlisthandler (places all the data in a specified column in the result set in a list)

Keyedhandler (sets all the data in the result set to the column name key, the data to the value in the Map collection, and then the map collection as the value, the key is specified and placed in a large map)

Maphandler (the first row of data in the result set is placed in a map column named key, data is a value)

Maplisthandler (place each row of data in the result set in a map, and multiple maps in a list)

Scalarhandler (Put the data of the specified column in a list)

14.JdbcUtils Frame

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.