问题描述
从同事哪里把一个工程拷到我的eclipse里面用的是mysql5.1tomcat5.5hibernate3tomcat启动正常,但是只要对数据库进行操作的都报错。。Initializingc3p0pool...com.mchange.v2.c3p0.PoolBackedDataSource@7bc0aa[connectionPoolDataSource->com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@18be602[acquireIncrement->1,acquireRetryAttempts->30,acquireRetryDelay->1000,autoCommitOnClose->false,automaticTestTable->null,breakAfterAcquireFailure->false,checkoutTimeout->0,connectionTesterClassName->com.mchange.v2.c3p0.impl.DefaultConnectionTester,factoryClassLocation->null,forceIgnoreUnresolvedTransactions->false,idleConnectionTestPeriod->3000,initialPoolSize->5,maxIdleTime->50000,maxPoolSize->20,maxStatements->100,maxStatementsPerConnection->0,minPoolSize->5,nestedDataSource->com.mchange.v2.c3p0.DriverManagerDataSource@bcd898[description->null,driverClass->null,factoryClassLocation->null,jdbcUrl->jdbc:mysql://localhost:3306/db_flowershop,properties->{user=******,password=******}],preferredTestQuery->null,propertyCycle->300,testConnectionOnCheckin->false,testConnectionOnCheckout->false,usesTraditionalReflectiveProxies->false],factoryClassLocation->null,numHelperThreads->3,poolOwnerIdentityToken->7bc0aa]Hibernate:selectcategory0_.IDasID,category0_.CateNameasCateName0_,category0_.CateDescasCateDesc0_fromdb_flowershop.categorycategory0_orderbycategory0_.IDHibernate:selectmerchandis0_.IDasID,merchandis0_.MerNameasMerName3_,merchandis0_.PriceasPrice3_,merchandis0_.SPriceasSPrice3_,merchandis0_.MerModelasMerModel3_,merchandis0_.PictureasPicture3_,merchandis0_.MerDescasMerDesc3_,merchandis0_.SpecialasSpecial3_,merchandis0_.numasnum3_,merchandis0_.CategoryasCategory3_fromdb_flowershop.merchandisemerchandis0_where(merchandis0_.Special=0)orderbymerchandis0_.IDdesclimit?org.hibernate.exception.SQLGrammarException:couldnotexecutequeryatorg.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)atorg.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)atorg.hibernate.loader.Loader.doList(Loader.java:1596)atorg.hibernate.loader.Loader.list(Loader.java:1577)atorg.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:890)atorg.hibernate.impl.SessionImpl.list(SessionImpl.java:844)atorg.hibernate.impl.QueryImpl.list(QueryImpl.java:74)atcom.txn.service.MerServiceImpl.browseMer(MerServiceImpl.java:243)atcom.txn.struts.action.MerAction.browseIndexMer(MerAction.java:40)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:597)atorg.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)atorg.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)atorg.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)atorg.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)atorg.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)atorg.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:627)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:729)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atcom.txn.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:33)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)atorg.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)atorg.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)atorg.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)atorg.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)atjava.lang.Thread.run(Thread.java:619)Causedby:java.sql.SQLException:Unknowncolumn'merchandis0_.num'in'fieldlist'atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)atcom.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)atcom.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1625)atcom.mysql.jdbc.Connection.execSQL(Connection.java:2297)atcom.mysql.jdbc.Connection.execSQL(Connection.java:2226)atcom.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1812)atcom.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1657)atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:75)atorg.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)atorg.hibernate.loader.Loader.getResultSet(Loader.java:1272)atorg.hibernate.loader.Loader.doQuery(Loader.java:391)atorg.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)atorg.hibernate.loader.Loader.doList(Loader.java:1593)...35more
解决方案
解决方案二:
我的配置文件如下:?xmlversion='1.0'encoding='UTF-8'?><!DOCTYPEhibernate-configurationPUBLIC"-//Hibernate/HibernateConfigurationDTD3.0//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!--GeneratedbyMyEclipseHibernateTools.--><hibernate-configuration><session-factory><!--配置JDBC连接属性--><propertyname="myeclipse.connection.profile">MySQL_JDBC</property><propertyname="connection.url">jdbc:mysql://localhost:3306/db_flowershop?useUnicode=true&characterEncoding=gb2312</property><propertyname="connection.username">root</property><propertyname="connection.password"></property><propertyname="connection.driver_class">com.mysql.jdbc.Driver</property><propertyname="dialect">org.hibernate.dialect.MySQLDialect</property><!--解决HQL查询中直接使用中文的问题--><propertyname="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property><!--配置C3P0连接池属性--><propertyname="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property><propertyname="hibernate.c3p0.max_size">20</property><propertyname="hibernate.c3p0.min_size">5</property><propertyname="hibernate.c3p0.timeout">50000</property><propertyname="hibernate.c3p0.max_statements">100</property><propertyname="hibernate.c3p0.idle_test_period">3000</property><!--在控制台显示SQL语句--><propertyname="show_sql">true</property><!--注册ORM映射文件--><mappingresource="com/txn/entity/Category.hbm.xml"/><mappingresource="com/txn/entity/Admin.hbm.xml"/><mappingresource="com/txn/entity/Orders.hbm.xml"/><mappingresource="com/txn/entity/Merchandise.hbm.xml"/><mappingresource="com/txn/entity/Cart.hbm.xml"/><mappingresource="com/txn/entity/Userlevel.hbm.xml"/><mappingresource="com/txn/entity/User.hbm.xml"/><mappingresource="com/txn/entity/Message.hbm.xml"/><mappingresource="com/txn/entity/Items.hbm.xml"/><mappingresource="com/txn/entity/Announce.hbm.xml"/></session-factory></hibernate-configuration>
解决方案三:
咋没人关注下呢?
解决方案四:
该回复于2010-04-16 17:08:02被版主删除
解决方案五:
ORM文件和表结构字段有差异或者生成的POJO有问题Causedby:java.sql.SQLException:Unknowncolumn'merchandis0_.num'in'fieldlist'
解决方案六:
http://www.codefin.net/2007/05/hibernate-and-mysql-connection-timeouts.html这个是我昨天解决跟你类似数据库问题找的一个英文网站,比起我的问题来,我看更适合于你,可以耐心的看一下
解决方案七:
认同4楼检查下字段映射
解决方案八:
org.hibernate.exception.SQLGrammarException:couldnotexecutequery1.SQL语句出错了...你可以看到输出来的sql,那拿到DB里面跑,能跑成功吗?2.hbm.xml文件中去掉category="DBname";