Https://zhidao.baidu.com/question/540539955.html?fr=iks&word=jdbc+sql%D3%EF%BE%E4&ie=gbk
JDBC Java Database INSERT statement error
Your sister's, wrote the placeholder you don't have to fill in, SQL of course, the report of the SQL is incomplete
Two scenarios
A. Four question marks after valuses write the parameters directly
B. Using import java.sql.PreparedStatement; PreparedStatement method under Package
A pre-programmed way to populate an example
PreparedStatement PS = null;
sql = "INSERT into record (cid,bid,mid,borrowdate,returndate) VALUES (?,?,?,?,?)";
Ps.setint (1, first value);
Ps.setint (2, second value);
Ps.setint (3, third value);
Ps.setint (4, fourth value);
Submit 1234 must write setint are examples of what types of fields you see yourself
Ps.executeupdate ();
Example:
String sql= "" +
"INSERT INTO Shopping" +
"(User_name,sex,age,birthday,email,mobile," + (note the usage of the "+" sign, I missed a plus sign, resulting in an error syntax error on token VALUES ("", delete this token, syntax error)
"Create_user,create_date,update_user,update_date,isdel)" +
"VALUES (" +
"?,?,?,?,?,?,?, current_date (),?, current_fste (),?)";
Or
String sql= "INSERT into shopping (User_name,sex,age,birthday,email,mobile,create_user,create_date,update_user, Update_date,isdel) VALUES (?,?,?,?,?,?,?, current_date (),?, current_fste (),?) ";
The following SQL statement is populated with parameters:
PreparedStatement ptmt=conn.preparestatement (SQL); Compiling SQL statements
Ptmt.setstring (1, G.getuser_name ()); Passing parameters in
Ptmt.setint (2,g.getsex ());
Ptmt.setint (3, G.getage ());
Ptmt.setdate (4, (Date) g.getbirthday ());
Ptmt.setstring (5,g.getemail ());
Ptmt.setstring (6, G.getmobile ());
Ptmt.setstring (7, G.getcreate_user ());
Ptmt.setstring (8, G.getupdate_user ());
Ptmt.setint (9,g.getisdel ());
Ptmt.execute ();
JDBC Java Database INSERT statement