日期:2014-05-17  浏览次数:20750 次

JSP 更新 MySQL 语句时遇到错误了= =
String sql="update thing set tname="+name+",tprice="+price+",tdetail="+pho+",tnum="+no+" where tID='"+id+"'";
System.out.println(sql);
try {
st.executeUpdate(sql);
st.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



报错:
update thing set tname=,tprice=,tdetail=,tnum= where tID='null'
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'tprice=,tdetail=,tnum= where tID='null'' at line 1
路过的大神帮帮忙吧T T

------解决方案--------------------
tID='"+id+"'多了个''吧,或者前面的tname="+name+",tprice="+price+",tdetail="+pho+",tnum="+no+"少了'',你可以试一下