请教JDBC delete 语句的问题

zcxie2008 zcxie2008 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

DELETE from roleNperm WHERE roleID=104 AND permCode="2";

其中roleID为Integer类型,permCode为varchar(4)类型
以上语句在MySQL中可以执行,并可以删除对应的行,但在JDBC中,我使用以下语句:


public void delRolePerm(String rolesID, String permCode) {
try {
db.connect();
String sql1 = "delete from rolenperm where roleID="+rolesID + "and permCode=\""+permCode+"\"";
db.stat = db.conn.createStatement();
db.stat.executeUpdate(sql1);

} catch(Exception e) {
e.printStackTrace();
} finally{
db.close();
}
}


出现的错误是:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 'permCode="2"' at line 1

请教为什么错,该如何处理?
想通过两个参数来删除表中的一行,该如何写sql那个String? 谢谢!
...全文

相关推荐

评论 17
收藏 已收藏
分享
返回顶部
zcxie2008
Web 开发 81,107 成员 341,720 内容