2017-02-08 107 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

相關問題