首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

请帮小弟我看看语法上有什么有关问题吗?奇怪

2012-01-07 
请帮我看看语法上有什么问题吗?奇怪?进行对数据库的删除操作,代码如下:Stringsql DELETE*FROMusercustom

请帮我看看语法上有什么问题吗?奇怪?
进行对数据库的删除操作,代码如下:
String   sql= "DELETE   *   FROM   usercustomer   WHERE   customerid= "+request.getParameter( "customerid ")+ ",ascription= ' "+(String)session.getAttribute( "userid ")+ " ' ";
stmt.executeUpdate(sql);

但提示我错误:
javax.servlet.ServletException:   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   '*   FROM   usercustomer   WHERE   customerid=2,ascription= 'abcd ' '   at   line   1


[解决办法]
DELETE FROM .........

不要*
[解决办法]
1)去掉*;
2)加上“and”在Where条件里;
3)Sql中的变量取出来,看的清晰。
String customerid = request.getParameter( "customerid ");
String ascription = (String)session.getAttribute( "userid ");
String sql=
"DELETE FROM usercustomer "+
"WHERE customerid= "+customerid+
"and ascription= "+ascription;
stmt.executeUpdate(sql);
[解决办法]
这样才是正确的:

String sql= "DELETE FROM usercustomer WHERE customerid= "+request.getParameter( "customerid ")+ "and ascription= ' "+(String)session.getAttribute( "userid ")+ " ' ";
stmt.executeUpdate(sql);

不能要*
也不能要,应该把,改为 AND

[解决办法]
(String)session.getAttribute( "userid ")应该改为:

((String)session.getAttribute( "userid ")).replaceAll( " ' ", " ' ' ")

热点排行