The use of batch update in JdbcTemplate, the connection and difference between BigDecimal and styling

Source: Internet
Author: User

1 //jdbctemplate Batch New use Menu_id_list is the front-end page passed to the back-end control layer, and then passed from the control layer to the implementation layer list2 3 //JdbcTemplate is a spring jdbctemplate that is instantiated by annotations.4 5  Public intInsertempmenu (FinalString Emp_id_,FinalList<string> menu_id_list, map<string, object>operator) {6         if(Menu_id_list = =NULL|| Menu_id_list.size () = = 0) {//common ways of judging7             return0;8         }9 TenString sql = "INSERT into Om_empmenu (id_, emp_id_, menu_id_) VALUES (?,?,?)"; OneBatchPreparedStatementSetter Batch =NewBatchPreparedStatementSetter () { A              Public voidSetvalues (PreparedStatement PS,intIthrowsSQLException { -Ps.setstring (1, Baseutils.getuuid ()); -Ps.setstring (2, emp_id_); thePs.setstring (3, Menu_id_list.get (i)); -             } -  -              Public intgetbatchsize () { +                 returnmenu_id_list.size (); -             } +         }; A         returnjdbctemplate.batchupdate (SQL, Batch). length; at}

The API class BigDecimal provided in the Java.math package is used to bigdecimal:java the number of more than 16 significant bits. Double-precision floating-point variable double can handle a 16-bit valid number. In practical applications, larger or smaller numbers need to be calculated and processed. float and double can only be used for scientific calculations or engineering calculations, and Java.math.BigDecimal are used in commercial calculations.

When the number taken out of the database is BigDecimal, the data needs to be bigdecimal-shaped, then the associated method is called, the value is obtained, the common Method Doublevalue (), Intvalue (). String type can be directly shaped

Double Avl_amount_ = ((BigDecimal) matyearplansum.get ("Amount_"). Doublevalue ();

(String) Matmonthplan.get ("Mat_desc_")

Instead of using the BigDecimal, you can use the type that you set for yourself if you are getting new values for the data that you have obtained, and you do not need to use it in the map.

1  for(Map<string, object>matyearplansum:matyearplansumlist) {2Avl_amount_ = ((BigDecimal) matyearplansum.get ("Amount_") . Doublevalue ();3Matyearplansum.put ("Avl_amount_", Avl_amount_);4                  for(Map<string, object>matmonthplanhis:matdeptmonthplanspentbudget) {5                     if(Matyearplansum.get ("Mat_no_"). Equals (Matmonthplanhis.get ("Mat_no_"))) {6                         if(Matyearplansum.get ("Amount_")! =NULL&& matmonthplanhis.get ("Spent_amount_")! =NULL) {7Avl_amount_ = ((BigDecimal) matyearplansum.get ("Amount_"). Doublevalue ()-((BigDecimal) matmonthplanhis.get ("Spent_ Amount_ ") . Doublevalue ();8                         }9Matyearplansum.put ("Avl_amount_", Avl_amount_);Ten                          Break; One                     } A                 } -             } -  for(Map<string, object>matmonthplan:matmonthplanlist) { the                  for(Map<string, object>matyearplansum:matyearplansumlist) { -                     if(Matmonthplan.get ("Mat_no_"). Equals (Matyearplansum.get ("Mat_no_"))) { -                         if(Matyearplansum.get ("Enable_amount_")! =NULL&& matmonthplan.get ("Amount_")! =NULL) { -Enable_amount_ = ((BigDecimal) matmonthplan.get ("Amount_") . Doublevalue (); +Enable_amount_ = (Double) matyearplansum.get ("Enable_amount_") +enable_amount_;//For example here, double -                         } +Matmonthplan.put ("Enable_amount_", Enable_amount_); A                          Break; at                     } -                 } -}

Common error: caused by:java.sql.sqlexception:ora-00911: Invalid character is because the concatenation of the SQL statement after a semicolon. You do not need to add a semicolon after the SQL statement using spring JdbcTemplate

The To_date () function converts a character type to a date type in a certain format:
Specific usage: to_date (' 2004-11-27 ', ' yyyy-mm-dd '), the former is a string, the latter is a conversion date format, note that before and after the two to a corresponding.
such as; To_date (' 2004-11-27 13:34:43 ', ' yyyy-mm-dd hh24:mi:ss ') will get specific time

The use of batch update in JdbcTemplate, the connection and difference between BigDecimal and styling

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.