2012-02-24 74 views
0

執行以下程序是給我的錯誤是,錯誤而在數據庫中插入圖像

Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatement.setBlob(ILjava/io/InputStream;)V 
    at ImageStore.main(ImageStore.java:28) 

我用ojdbc14.jar的和我的Oracle版本是9.0.1.1.1

public class ImageStore { 

/** 
* @param args 
* @throws Exception 
*/ 
public static void main(String[] args) throws Exception { 
    Class.forName("oracle.jdbc.driver.OracleDriver"); 

    Connection con = DriverManager 
      .getConnection("jdbc:oracle:thin:@localhost:1521:orcl", 
        "usrname", "password"); 

String sql="update items set image=? where id=1"; 
    //String sql="select * from price"; 
    PreparedStatement ps=con.prepareStatement(sql); 
    File f=new File("E:/Images/s.jpg"); 
    InputStream fos= new FileInputStream(f); 

    ps.setBlob(1, fos); 

    ps.execute(); 
    /*while(rs.next()) 
     System.out.println(rs.getInt(1)); 
*/ 
    ps.close(); 
    con.close(); 


} 

}

請幫

+0

添加(或鏈接)完整的錯誤日誌,請。不只是你認爲合適的那一行。 – Alfabravo 2012-02-24 19:22:19

+0

你正在運行什麼版本的JRE? – Alex 2012-02-24 19:28:12

+0

我使用jre6運行 – 2012-02-25 04:48:12

回答

1

我只好也插入圖像的數據庫和它的工作方式是在下列

  1. 圖像轉換爲字節陣列

  2. 使用的setBinaryStream其中數據是字節

    preparedStatement.setBinaryStream(1,新ByteArrayInputStream的(數據),data.length)的陣列;

編輯:這種技術的倒臺是用於陣列

0

AbstractMethodError整數限制大小表明,您沒有與合適的驅動程序的工作。如果您使用了Java5或以上,請嘗試下載相應的驅動程序ojdbc(ojdbc14.jar的是java1.4)

http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-111060-084321.html

+0

我使用jdk1.3,1.4,1.5和1.6編譯我的程序。但與所有這些我得到的錯誤。 – 2012-02-25 04:50:02

+0

你可以發佈編譯和執行的類路徑嗎?也可以嘗試使用jre6編譯和運行ojdbc6.jar的類。 – Alex 2012-02-26 05:01:14