2017-02-08 113 views
1

我写了一段代码,可以帮助用户使用JDBC将图像保存在oracle数据库中。上传照片并将其保存到Oracle数据库10g

PreparedStatement ps =con.prepareStatement("insert into employee values(?,?)"); 
ps.setString(1,name); 
ps.setBlob(2,inputStream); 

但是,当我试图运行的代码,它得到一个错误

java.lang.AbstractMethodError: Method oracle/jdbc/driver/T4CPreparedStatement.setBlob(ILjava/io/InputStream;)V is abstract

这是怎么造成的,我该如何解决呢?

+0

这个错误几乎总是意味着你正在使用不同版本的库(在这种情况下,JDBC驱动程序或支持库)。 – chrylis

+0

@AxelH,谢谢,但我已经下载了ojdbc6.jar,但它不工作。我也尝试过使用'setBinaryStream',但我仍面临同样的问题。 – Sampad

+0

@Sampad,你的JDK版本是什么?由于没有用于Oracle 10g的JDBC支持JDK 6,7或8,我不知道它是否可以从那里得到... – AxelH

回答

-1

尝试转换您的InputStream字节(第一),它作为参数传递给steBlob方法

如:

BufferedInputStream bis= new BufferedInputStream(inputStream); /// pass your inputStream here 
     int size=0; 
     byte[] bytes; 
     Blob blob = con.createBlob(); // create blob using connection obj 
     int length = 1; 
     int readCount=0; 
     System.out.println(img.getCanonicalPath()); 
     do { 
      bytes = new byte[bis.available()]; 
      readCount = bis.read(bytes); 
      blob.setBytes(length, bytes); ///populate chunks of data to the blob 
      length=length+readCount; 

      size= bis.available(); 
      //System.out.println(bis.read()); 
     }while (size > 0); 
     PreparedStatement st = con.prepareStatement("INSERT INTO TABLE VALUES (?,?)"); 
     st.setString(1, id); 
     st.setBlob(2, blob); 
     st.execute(); 
+0

谢谢,但你能帮我整理一下吗? – Sampad

相关问题