问题描述
严重:Servlet.service()forservletactionthrewexceptioncom.mysql.jdbc.exceptions.MySQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'.liberInfo_tliberinfo0_whereliberinfo0_.id=1'atline1atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)atcom.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)atcom.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)atcom.mysql.jdbc.Connection.execSQL(Connection.java:3283)atcom.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)atcom.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)atorg.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)atorg.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)atorg.hibernate.loader.Loader.getResultSet(Loader.java:1787)atorg.hibernate.loader.Loader.doQuery(Loader.java:674)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)atorg.hibernate.loader.Loader.doList(Loader.java:2213)atorg.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)atorg.hibernate.loader.Loader.list(Loader.java:2099)atorg.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)atorg.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)atorg.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)atorg.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)atorg.hibernate.impl.QueryImpl.list(QueryImpl.java:79)atorg.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:839)atorg.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)atorg.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:830)atorg.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:822)atsunyang.dao.liberInfo.LiberInfoDAOImpl.findById(LiberInfoDAOImpl.java:12)atsunyang.service.back.SysLiberInfoFacadeImpl.showLiberInfo(SysLiberInfoFacadeImpl.java:18)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:585)atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)atorg.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)at$Proxy2.showLiberInfo(UnknownSource)atsunyang.webtier.front.FrontAction.showLiberInfo(FrontAction.java:92)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:585)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)atorg.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)atsunyang.util.CharacterTrans.process(CharacterTrans.java:16)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:690)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atsunyang.util.LoginFilter.doFilter(LoginFilter.java:46)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(Thread.java:595)这是错误,下面是查询代码publicLiberInfofindById(Integerid){return(LiberInfo)getHibernateTemplate().find("fromLiberInfowhereid="+id).get(0);}请问是MYSQL的版本问题吗?我用的是HIBERNATE3.3MYSQL5.1
解决方案
解决方案二:
CompanyInfo是你的实体类名吗?与LiberInfo的对应关系配置好了吗
解决方案三:
"fromLiberInfo(为了防止错,这里最好写类的全名)asliberInfowhereliberInfo.id="+id
解决方案四:
谢谢。。我先改改试试看
解决方案五:
还是不行报错:严重:Servlet.service()forservletactionthrewexceptioncom.mysql.jdbc.exceptions.MySQLSyntaxErrorException:YouhaveanerrorinyourSQLsyntax;checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear'.liberInfo_tliberinfo0_whereliberinfo0_.id=1'atline1这是改后的DAOpublicLiberInfofindById(Integerid){return(LiberInfo)getHibernateTemplate().find("fromLiberInfoasliberInfowhereliberInfo.id="+id).get(0);}
解决方案六:
如果不对你就这样写吧StringqueryString="fromLiberInfoasliberInfowhereliberInfo.id=?";QueryqueryObject=getSession().createQuery(queryString);queryObject.setParameter(0,id);return(LiberInfo)queryObject.list().get(0);
解决方案七:
就直接写进findById里面么
解决方案八:
如果还不对,你就把映射文件发上来。
解决方案九:
引用6楼tssjj的回复:
就直接写进findById里面么
对,但我没处理异常,你需要自己处理。
解决方案十:
<hibernate-mapping><classname="sunyang.domain.liberInfo.LiberInfo"table="liberInfo_t"schema="dbo"catalog="liber_db"><idname="id"type="java.lang.Integer"><columnname="id"/><generatorclass="native"/></id><propertyname="liberName"type="java.lang.String"><columnname="liberName"length="50"/></property><propertyname="curator"type="java.lang.String"><columnname="curator"length="50"/></property><propertyname="tel"type="java.lang.String"><columnname="tel"length="50"/></property><propertyname="address"type="java.lang.String"><columnname="address"length="50"/></property><propertyname="email"type="java.lang.String"><columnname="email"length="50"/></property><propertyname="url"type="java.lang.String"><columnname="url"length="50"/></property><propertyname="buildDate"type="java.util.Date"><columnname="buildDate"length="23"/></property><propertyname="introduce"type="java.lang.String"><columnname="introduce"/></property></class></hibernate-mapping>这是hbm.xml,按照你的写了。还是不对。。同样的错误
解决方案十一:
publicclassLiberInfo{privateIntegerid;//privateStringliberName;//privateStringcurator;//privateStringtel;//privateStringaddress;//privateStringemail;//privateStringurl;//privateDatebuildDate;//privateStringintroduce;//publicLiberInfo(){}publicIntegergetId(){returnthis.id;}publicvoidsetId(Integerid){this.id=id;}publicStringgetLiberName(){returnthis.liberName;}publicvoidsetLiberName(StringliberName){this.liberName=liberName;}publicStringgetCurator(){returnthis.curator;}publicvoidsetCurator(Stringcurator){this.curator=curator;}publicStringgetTel(){returnthis.tel;}publicvoidsetTel(Stringtel){this.tel=tel;}publicStringgetAddress(){returnthis.address;}publicvoidsetAddress(Stringaddress){this.address=address;}publicStringgetEmail(){returnthis.email;}publicvoidsetEmail(Stringemail){this.email=email;}publicStringgetUrl(){returnthis.url;}publicvoidsetUrl(Stringurl){this.url=url;}publicDategetBuildDate(){returnthis.buildDate;}publicvoidsetBuildDate(DatebuildDate){this.buildDate=buildDate;}publicStringgetIntroduce(){returnthis.introduce;}publicvoidsetIntroduce(Stringintroduce){this.introduce=introduce;}}这个是GETSET成立时间privateStringintroduce;//公司的简介
解决方案十二:
你这id是主键其实都不用刚才那么写这样就可以(LiberInfo)getSession().get("sunyang.domain.liberInfo.LiberInfo",id);也可以这样StringqueryString="fromsunyang.domain.liberInfo.LiberInfoasliberInfowhereliberInfo.id=?";QueryqueryObject=getSession().createQuery(queryString);queryObject.setParameter(0,id);return(LiberInfo)queryObject.list().get(0);那个地方用全类名。
解决方案十三:
不会是版本的问题吧
解决方案十四:
按照11楼我说的更改过了吗?
解决方案十五:
嗯。不行。一样的错误
解决方案:
生成的sql好像是对的liberInfo_tliberinfo0_whereliberinfo0_.id=1不应该是版本的问题啊。
解决方案:
你用一个sql到mysql命令行上执行看看有没有问题,如果都有问题,说明数据库就有问题。如果没有问题你再用生成的sql执行看看。挺奇怪的。
解决方案:
怎么办呢
解决方案:
好吧我试试
解决方案:
看来是sql语句出错了,(selectmfromLiberInfomwherem.username=?).setString(0,username).uniqueResult();也不用list了直接返回的就是一个对象。希望你能尽快解决问题。
解决方案:
还是不行啊