jsp中sql语句条件中包含中文字符出现错误

demonapple 2011-01-12 04:31:47
我用的是access数据库
在查询分析器里面这句可以执行

select * from tb_blog_article where article_cljg="待观察"


但是放到jsp代码中就会出现错误。The left-hand side of an assignment must be a variable

Statement stmt1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql1="select * from tb_blog_article where article_cljg="待观察"";
ResultSet Rs1=stmt1.executeQuery(sql1);


哪里出错了?应该怎么写?
...全文
174 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ma309385560 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 liutianxiong888 的回复:]
select * from tb_blog_article where article_cljg="待观察"

这中文应该是单引号呀,看下改
select * from tb_blog_article where article_cljg='待观察'
[/Quote]

+1
xiangfeidecainiao 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xufebruary 的回复:]
你应该使用转义字符来处理 sql 语句中的 引号

String sql1="select * from tb_blog_article where article_cljg=\"待观察\"";
[/Quote]
[Quote=引用 8 楼 luman2002 的回复:]
String sql1="select * from tb_blog_article where article_cljg='待观察'";
[/Quote]
宁波朱超 2011-01-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 demonapple 的回复:]
我用的是access数据库
在查询分析器里面这句可以执行

SQL code

select * from tb_blog_article where article_cljg="待观察"



但是放到jsp代码中就会出现错误。The left-hand side of an assignment must be a variable

JScript code

St……
[/Quote]

不要用字符串拼接 用预编译的方式

字符串拼接 我要是知道你的数据库名 我能把你数据库给删了。
luman2002 2011-01-12
  • 打赏
  • 举报
回复
String sql1="select * from tb_blog_article where article_cljg='待观察'";
Fortunatee 2011-01-12
  • 打赏
  • 举报
回复
用preparedstatement吧,养成好习惯
bjvfubj 2011-01-12
  • 打赏
  • 举报
回复
有时候单引号不可以哦,好像跟类型有关,有时候要用转义字符才可以哦
影随行 2011-01-12
  • 打赏
  • 举报
回复
你应该使用转义字符来处理 sql 语句中的 引号

String sql1="select * from tb_blog_article where article_cljg=\"待观察\"";
LS1firesoar 2011-01-12
  • 打赏
  • 举报
回复
String sql1="select * from tb_blog_article where article_cljg="待观察"";
因该是
String sql1="select * from tb_blog_article where article_cljg="+'待观察';
liuchao1989 2011-01-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 liutianxiong888 的回复:]
select * from tb_blog_article where article_cljg="待观察"

这中文应该是单引号呀,看下改
select * from tb_blog_article where article_cljg='待观察'
[/Quote]+1 数据库中的字符串是用 ''。
lixiaoyan3 2011-01-12
  • 打赏
  • 举报
回复
单引号。双引号是错误的。
Spring89 2011-01-12
  • 打赏
  • 举报
回复
select * from tb_blog_article where article_cljg="待观察"

这中文应该是单引号呀,看下改
select * from tb_blog_article where article_cljg='待观察'

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧