hello_worldW 2016-11-27 02:46 采纳率: 50%
浏览 1315
已结题

javaweb中preparedstatement执行条件为中文的语句时出现错误

String sql = "select top 30 * from msgInfo where ID in(select top 30 ID from msgInfo where chatRoom=? order by chatTime DESC) order by chatTime" ;
PreparedStatement ps = conn.preparedStatement(sql) ;
ps.setString(1,request.getSession().getAttribute("CHAT_ROOM").toString()) ;
错误: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 '30 * from msgInfo where ID in(select top 30 ID from msgInfo where chatRoom='新' at line 1
中文是新闻

  • 写回答

2条回答 默认 最新

  • liustarstar 2016-11-27 04:12
    关注

    (select top 30 ID from msgInfo where chatRoom=? order by chatTime DESC)这样是要查前30条的ID where chatRoom=? 这个位
    “=”匹配只会有一条的输出吧 如果你的chatRoom是字符串的类型 应该不是中文的问题 你把“=”改成like“试试 我瞎猜的 不一定对

    评论

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn