Personal talk about Java splicing SQL statement principle.
This principle is personal sentiment (not guaranteed to be completely correct)
The first rule is to write a complete string first. (For example, "SELECT * from Users where id= (id+1)")
All variables need to precede it with +, and the preceding is to add ", if not later", then you must also add + ".
The second principle if you encounter parentheses (id+1), the plus sign must die in parentheses, preceded by +, and the front is ", and the rear is +"
The third principle, if the late encounter is the variable behind there is ", it is better simply, omitted directly."
The Forth principle, if it is not a SQL statement, encounters a hyperlink statement, encounters a ", no matter what, is not", directly at the front and rear ends plus "", connect it together.
This article is from the "Jane's Life" blog, please be sure to keep this source http://1464490021.blog.51cto.com/4467028/1922865
How to stitch SQL or other variable statements in Java