我有一個問題,在獎勵表中插入值。嘗試解決它,並找到其他職位,但我找不到任何解決方案。列數不匹配在mysql數據庫的第1行值計數
String sql1 = "INSERT INTO rewards(project_id, 1st_reward,1st_description, 2nd_reward, 2nd_description, 3rd_reward, 3rd_description, 4th_reward, 4th_description, 5th_reward, 5th_description) "
+ "values('"
+ projectId
+ "','"
+ rwd1.getText().toString()
+ "','"
+ rwd1Desc.getText().toString()
+ "','"
+ rwd1.getText().toString()
+ "','"
+ rwd2.getText().toString()
+ "','"
+ rwd2Desc.getText().toString()
+ "','"
+ rwd3.getText().toString()
+ "','"
+ rwd3Desc.getText().toString()
+ "','"
+ rwd4.getText().toString()
+ "','"
+ rwd4Desc.getText().toString()
+ "','"
+ rwd5.getText().toString()
+ "','"
+ rwd5Desc.getText().toString()
+ "')";
stmt.executeUpdate(sql1);
這是我們如何組裝查詢。 – ppeterka
這種裝配查詢,是不是最佳實踐? –
是的,您應該使用預準備語句,而不是連接字符串。這是更安全,友善,通常更好。 – ppeterka