今天朋友叫俺去帮忙调一下程序,是Hibernate+MySql的问题,可以向数据库中插入数据,但是在查询的时候,抛出如下异常:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.lk.yk.hibernate.operation.TypeOperation.SelectAll(TypeOperation.java:55)
at com.lk.yk.hibernate.operation.TypeOperation.main(TypeOperation.java:84)
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.lk.yk.hibernate.operation.TypeOperation.SelectAll(TypeOperation.java:55)
at com.lk.yk.hibernate.operation.TypeOperation.main(TypeOperation.java:84)
** END NESTED EXCEPTION **
Last packet sent to the server was 47 ms ago.
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3176)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1153)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1266)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 7 more
Exception in thread "main" java.lang.NullPointerException
at com.lk.yk.hibernate.operation.TypeOperation.main(TypeOperation.java:84)
这个异常,俺还是第一次碰到过,看了看查询方法,也没有错呀,又重新试了一下,还不同样的情况,看来朋友没有误报,没辙,谁让咱水平浅来呢,走人,到GOOGLE上逛去,一查说是驱动JAR不对,google确实是好东西,一查就有,呵呵,那个舒服呀,问朋友服务器是用的什么版本的MYSQL,说是5.0的<其实不是5.0的>,俺就从网上下了一个相应版本的JAR,呵呵,俺想这次可行了吧,呵呵,没有想到,不成,还是不行。这下俺是彻底的没辙了,水平浅,那咱找别人,又找了一个哥们过来,三两下,解决了,一问,只不过换了一个版本更底的JAR,我那个恨呀。
唠叨这么多,不为别的,呵呵,俺只想在这里给自己敲一下警钟,同样是解决问题,为什么别人能找到问题所在,而咱找不到,应该想想这个问题,虽然工作经验少,但这不应该成为狡辩的理由,应该深刻的反思一下......该去增强一下内功了,
呵呵,不多说了,走人,俺先反思,去练功去了,终有一天俺也会成为一个内功深厚的武林高手的......