为了账号安全,请及时绑定邮箱和手机立即绑定

老师,大神们 看一下它存图的时候报这样的错

java.lang.AbstractMethodError: Method com/mysql/jdbc/PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V is abstract

at com.mysql.jdbc.PreparedStatement.setBinaryStream(PreparedStatement.java)

at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$5$1.doBind(BlobTypeDescriptor.java:133)

at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$2$1.doBind(BlobTypeDescriptor.java:90)

at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:93)

at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)

at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)

at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)

at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2786)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3064)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)

at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)

at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)

at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)

at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)

at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)

at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)

at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)

at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)

at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)

at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)

at zkj.StudentsTest.destory(StudentsTest.java:52)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.runners.ParentRunner.run(ParentRunner.java:300)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


@Test

public void testWriteBlob() throws Exception{

Students s=new Students(1, "张三丰","男",new Date(),"武当山");

File f=new File("d:"+File.separator+"boy.jpg");

InputStream input=new FileInputStream(f);

Blob image=Hibernate.getLobCreator(session).createBlob(input,input.available());

s.setPicture(image);

session.save(s);

}

}


正在回答

3 回答

去下一个mysql-connector-java-5.1.40,重新build path吧。我刚才也是这样

0 回复 有任何疑惑可以回复我~
#1

谁的浮生乱了流年

可是 我用的就是5.1.40的驱动a 这是为什么呢
2017-02-26 回复 有任何疑惑可以回复我~
#2

慕粉4279226 回复 谁的浮生乱了流年

你解决了吗? 我换了好多个jar包都没用
2017-05-16 回复 有任何疑惑可以回复我~

因为你的数据库连接驱动版本太低了,没有重写PreparedStatement的setBlob(int index,InputStream inputstream)方法,只有setBlob(int index,Blob blob)所以你要重新下载一个mysql-connector-java.jar的新版本。

mysql-connector-java-5.1.39-bin.jar这个版本就可以使用

4 回复 有任何疑惑可以回复我~
#1

暮色如虹

我也出现了这个问题,亲测,好用。感谢老铁。
2017-08-22 回复 有任何疑惑可以回复我~

其他的代码呢

0 回复 有任何疑惑可以回复我~
#1

qq_赵成冬_0

我也是这个错误,解决了吗
2016-08-15 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

老师,大神们 看一下它存图的时候报这样的错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信