我是否将以下内容插入到具有四列message_id(自动递增)的message_sender,message_reciever,message_body的表中,从而丢失了错误。我已经检查了类似的问题,但没有找到解决方案。'''
<% String sender_id = request.getParameter("message_sender");
String reciever_id = request.getParameter("message_reciever");
String message = request.getParameter("message_body");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/fyp", "root", "Kmd116352323!");
Statement st = con.createStatement();
st.executeUpdate("INSERT INTO messages(message_sender,message_reciever,message_body) VALUES('"+sender_id+", "+reciever_id+" , "+message+" ')");
out.println("Your request has been noted."
+ " Please return to your user profile or log out");
} catch(Exception e){
out.println(e);
}
%>
这不正确:
VALUES('"+sender_id+", "+reciever_id+" , "+message+" ')
您有一个包装所有值的'
...这意味着sql会认为您只发送1个值。如果它们都是文本值,则应如下所示:
VALUES('"+sender_id+"', '"+reciever_id+"' , '"+message+"')
如果您知道某些值是INT类型,则不需要该值的'
:
VALUES("+sender_id+", "+reciever_id+" , '"+message+"')
文本值需要用'
换行