自学内容网 自学内容网

SpringMVC中出现的sql语句错误

1、原sql语句:select `major_id` AS 'majorId' ,`major_name` AS 'majorName',tuition,`dept_id` as 'deptId' from tb_major where major_id = ?

出现问题:Request processing failed: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [select `major_id` AS 'majorId' ,`major_name` AS 'majorName',tuition,`dept_id` as 'deptId' from tb_major where major_id = ?]

解决办法:

String sql = "select `major_id` AS 'majorId' ,`major_name` AS 'majorName',tuition,`dept_id` as 'deptId' from tb_major where major_id = ' "+majorId.trim()+" ' ";

2、原语句:String sql = "update tb_major set major_name =? and tuition =? where major_id=?";

出现的问题与第一题类似:

提示:bad SQL grammar

解决办法:

String sql = "update tb_major set major_name =? ,tuition =? where major_id=?";

将and改为 , (逗号)即可


原文地址:https://blog.csdn.net/weixin_53415203/article/details/142529546

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!