如题。
如果我不插入from字段,就没问题,就是将:
   String sql_send="insert into SMS(to,from,title,content,ptime) values('"+to+"','"+from+"','"+title+"','"+content+"','"+ptime+"')";
改成:
   String sql_send="insert into SMS(to,title,content,ptime) values('"+to+"','"+title+"','"+content+"','"+ptime+"')";
就OK但一旦插from字段,就报错:
数据库更新出错:[Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。究竟是怎么回事啊?究竟是我数据库设计错了还是其他问题啊?
大侠们快帮帮我啊,快愁死啦……
====数据库部分====
[SMS]    短信表
id       自动编号(主键)
to       收信者(文本,50)
from     发信者(文本,50)
title    标题(文本,200)
content  内容(备注)
ptime    发信时间(时间/日期)====表单部分====
<input name="to" type="hidden"  id="to" value="管理员"/><input name="from" type="text" class="colorblur" id="from" value="<%=Sess_tName%>" readonly="true"size="56"/>注:变量Sess_tName是已定义的session值<input name="title" type="text" class="colorblur" id="title" value="发短信测试标题" size="60" maxlength="40" /><textarea name="content" cols="60" rows="4" class="colorblur" id="content">发短信测试内容</textarea>
=====处理页面部分====
<% 
   request.setCharacterEncoding("gb2312");
   String to=new String(request.getParameter("to").getBytes("ISO-8859-1"));
   String from=new String(request.getParameter("from").getBytes("ISO-8859-1"));
   String title=new String(request.getParameter("title").getBytes("ISO-8859-1"));
   String content=new String(request.getParameter("content").getBytes("ISO-8859-1"));
   String ptime=(new java.util.Date()).toLocaleString(); 
   
   String sql_send="insert into SMS(to,from,title,content,ptime) values('"+to+"','"+from+"','"+title+"','"+content+"','"+ptime+"')";
   out.print(sql_send);   try
   {
      stmt.executeUpdate(sql_send);
  out.print("<script>alert('发送信息成功!请耐心等待回复。');document.location.href='msg_r.jsp';</script>");
}catch(Exception e)
     {

  //out.print("<script>alert('数据库更新出错:"+e.getMessage()+"');history.go(-1);</script>");
  out.print("数据库更新出错:"+e.getMessage());
 } //关闭连接
    if(conn!=null)
{
conn.close();
}
if(stmt!=null)
{
stmt.close();
}
}
%>

解决方案 »

  1.   

    同楼上的想法,想看看生成好的sql语句,有可能from变量中有某些字符破坏了sql语句
      

  2.   

    from 是关键字 字段不能起这个名字 换一个把  哪管是 “mfrom” 都行
      

  3.   

    给from字段名加个双引号,这样:insert into SMS(to,"from",title,content,ptime) values(.....)
      

  4.   

    from是关键字,会出现既不报错,又插不进去的问题。
    有些数据库为了区分关键字和表字段,在表字段前加distinct。
      

  5.   

    “有些数据库为了区分关键字和表字段,在表字段前加distinct”有这事儿???
      

  6.   

    恩 我也认为是from的问题 最好别用这种关键字作为字段  你换个别的名字 应该就没有问题了
      

  7.   

    是的,from是关键字,换个字段名