更新BLOB文件时出错 [英] Error in updating BLOB file

查看:137
本文介绍了更新BLOB文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:-

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:-字符串长度:5395

OutPut:- Length of string: 5395

错误:-

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)

错误行:-

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

我正在尝试将一个Blob文件(图像)存储到myblob表中,该表只有一个字段-BLOB. 任何机构都可以解释错误的原因及其解决方法吗? 提前thnks.

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.

推荐答案

可能遇到类型转换问题,请尝试在 int 上尝试 byte :

Probably facing a typecasting issue try byte instead on int:

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

这篇关于更新BLOB文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆