Error in updating BLOB file

邮差的信 提交于 2019-12-25 03:08:23

问题


Code:-

package jdbc;

import java.io.File;
import java.io.FileReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Properties;

public class Storing_Clob {

public static void main(String[] args) throws Exception {

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

    Properties p = new Properties();
    p.put("user", "system");
    p.put("password", "password");

    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",p);

    PreparedStatement pstmt = con.prepareStatement("update myclob set CLOB_VALUE=? where ID = 100");

    URL url = Storing_Clob.class.getResource("/images/clob1.txt");

    File file = new File(url.toURI());
    FileReader fr = new FileReader(file);

    pstmt.setCharacterStream(1,fr,(int)file.length());

    System.out.println("File size: "+(int)file.length());

    System.out.println("No of rows affected: "+pstmt.executeUpdate());

    con.close();

}

}

OutPut:- Length of string: 5395

Error:-

Exception in thread "main" java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java)
at jdbc.Storing_Image.main(Storing_Image.java:39)

Erroneous Line:-

        System.out.println("No of rows affected: "+pstmt.executeUpdate());

I am trying to store a blob file(image) into the myblob table.The table has only one field - BLOB. Can any body please explain the reason for the error and how to solve it? thnks in advance.


回答1:


Probably facing a typecasting issue try byte instead on int:

pstmt.setCharacterStream(1,fr,(byte)file.length());


来源:https://stackoverflow.com/questions/21513812/error-in-updating-blob-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!