为什么我的sql更新语句有问题?请赐教!

star123qiu 2002-05-16 10:28:39
有以下代码:
String sql="update table2 set '" + number + "'='"+score+"' where 学号='"+ id +"' and 姓名='" + name + "' and 班级='" + grade + "' " ;
try
{
conn=DriverManager.getConnection(connstr);
Statement stmt=conn.createStatement();
rs=stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ ex.getMessage());
}

其中:number ,score为 int;可是执行是抱错,如下:
E:\\JRun\\servers\\default\\default-app\\wangzhan\\xiugai.jsp:161: Error: The type of the left-hand side in this assignment, "java/sql/ResultSet", is not compatible with the type of the right-hand side expression, "int".

请帮帮我!
...全文
343 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
star123qiu 2002-05-16
  • 打赏
  • 举报
回复
rs=stmt.executeUpdate(sql);//这一行也有错
stmt.executeUpdate(sql);//去掉rs=
果真好使了!
我成功了!
多谢高手指教!
yangl 2002-05-16
  • 打赏
  • 举报
回复
set number=100

整型不需''
weidegong 2002-05-16
  • 打赏
  • 举报
回复
rs=stmt.executeUpdate(sql);//这一行也有错
stmt.executeUpdate(sql);//去掉rs=
或者int i=stmt.exe...
star123qiu 2002-05-16
  • 打赏
  • 举报
回复
字段名的单引号我也去掉了 ,改为
set number='100' 也不行啊
weidegong 2002-05-16
  • 打赏
  • 举报
回复
update table2 set 'number'='100'...
这个就不对了。字段名不需要包含单引号:set number='100' 即可
wwwfwww 2002-05-16
  • 打赏
  • 举报
回复
中文问题,你在后面out.print sql就知道了

81,122

社区成员

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

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