錯誤: nknown column 'xxxx' in 'where clause'
阿新 • • 發佈:2017-10-25
app ror -a col 相關 del dpa tid reflect
nknown column ‘sdsds‘ in ‘where clause‘
運行環境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse
錯誤:nknown column ‘sdsds‘ in ‘where clause‘
錯誤原因:數據庫查詢無用,可能很多寫sql語句都會遇到這個問題,從字面這意思很容易得出,意思是列名不存在的意思,在下面我的數據庫根本沒有這個所謂的列名,這個是因為我在查詢sql語句時候用到字符以及整形等,這裏改成整型就沒有問題
解決辦法:你查詢時候在對應的字符型沒有加上對應的單引號
錯誤代碼:
1### SQL: SELECT student_id as studentId,student_password as studentPassword FROM xxhh_table_user WHERE student_id=15301061 AND student_password=sdsds 2 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘sdsds‘ in ‘where clause‘ 3 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘sdsds‘ in ‘where clause‘4 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) 5 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) 6 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)7 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365) 8 at com.sun.proxy.$Proxy15.selectOne(Unknown Source) 9 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160) 10 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68) 11 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) 12 at com.sun.proxy.$Proxy21.selectByPrimaryKey(Unknown Source) 13 at com.xxhh.service.impl.LoginServiceImpl.selectByPrimaryKey(LoginServiceImpl.java:77) 14 at com.xxhh.controller.LoginController.selectUserAndPassword(LoginController.java:126) 15 at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source) 16 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 17 at java.lang.reflect.Method.invoke(Method.java:601) 18 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 19 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 20 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 21 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) 22 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) 23 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 24 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) 25 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) 26 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) 27 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
相關代碼:
錯誤: nknown column 'xxxx' in 'where clause'