当前位置:网站首页>Insert and update each database
Insert and update each database
2022-06-25 20:48:00 【Nishino_ shou】
mysql:
A trite question , Batch insertion occurs in the business , But some data need to be judged whether it exists , If it exists, it will be updated .
So in mysql among , Use on duplicate key update Can achieve this goal !
About the use of this method , There are many introductions on Baidu , I won't go into that here .
The main purpose is to save the problems encountered in the process of use .
1. Use jdbctemplate To operate the database , So dynamic sql On the spelling of , Note that the field names match , Otherwise, an error will be reported
Unknown column '***' in 'field list'You can still encounter jdbctemplate A deep pit problem of ,
template.queryForList, This method cannot return list object , Only single column values will be obtained list, For example, a table has ten fields , This will only return all of one field list.. When you use it to return objects , Errors will be reported, such as the following data :
Incorrect column count: expected 1, actual 102. Data table structure , The new time and update time fields are generally available , By default
`create_datetime` timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT ' Creation time ',
`update_datetime` timestamp(0) NULL DEFAULT CURRENT_TIMESTAMP(0) ON UPDATE CURRENT_TIMESTAMP(0) COMMENT ' Update time ',It will follow the data update to modify the corresponding time .
But combine on duplicate key update When you use it , If all fields are the same and already exist , Then the data will not be updated , Time will not be updated ( The main reason is that duplicate data is operated at that time , The time has not been updated , And scratched his head ..)
DM database :
DM As a domestic database , Insert and update , And db2 be similar .

use merge into The way , Take the primary key or index set in the table as the judgment condition , Update other fields , If it is new data, insert . Of course, the sql The definition is rough , It is good to look at , If you are using a predefined sql, May adopt stringbuilder Go to together , Reduce object creation .
And mysql The same thing is that it encounters duplicate data , Will not take the initiative to update , Only when a certain field or some field changes are found, the update operation will be performed .
边栏推荐
- Node connection MySQL
- Must see the summary! In depth learning era, you should read 10 articles to understand image classification!
- What are cookies in Web site development?
- [machine learning] machine learning from zero to mastery -- teach you to recognize handwritten digits using KNN
- Nmap is simple and practical
- Online yaml to XML tool
- Delete the page specified in PDF and merge pdf
- Mysqldumpslow out slow statements in the database
- Xshell mouse configuration
- The last core step of configuring theano GPU
猜你喜欢

Xshell mouse configuration

Lantern Festival, learning at the right time! Novice training camp attacks again, learning buff continues to fill up

Leetcode daily question - 28 Implement strstr() (simple)
Chrome plugin installation
Yanjiehua, editor in chief of Business Review: how to view the management trend of business in the future?
Introduction to the basics of kotlin language: lambda expression
New generation engineers teach you how to play with alluxio + ml (Part 2)
Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!

Heavy update! Yolov4 latest paper! Interpreting yolov4 framework
Cross project measurement is a good helper for CTOs and PMOS
随机推荐
Illustrated with pictures and texts, 700 pages of machine learning notes are popular! Worth learning
Lantern Festival, learning at the right time! Novice training camp attacks again, learning buff continues to fill up
Global netizens Yuanxiao created a picture of appreciating the moon together to experience the creativity of Baidu Wenxin big model aigc
How does zhiting home cloud and home assistant access homekit respectively? What is the difference between them?
The live registration is hot to start | the first show of Apache dolphin scheduler meetup in 2022!
Install and initialize MySQL (under Windows)
JS canvas drawing an arrow with two hearts
Interview records
SQL statement select summary
Common optimization of e-commerce server system architecture
IPtables
The secret of metaktv technology of sound network: 3D space sound effect + air attenuation + vocal blur
[machine learning] machine learning from zero to mastery -- teaching you how to use decision tree to predict contact lens types
Dice、Sensitivity、ppv、miou
This is a simple and cool way to make large screen chart linkage. Smartbi will teach you
node. JS express connect mysql write webapi Foundation
Popular understanding of deviation and variance in machine learning
Local variables and global variables in C language
Several ways to obtain domain administrator privileges
Mysqldumpslow out slow statements in the database