首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jaybird 2.1.6在blob字段中插入文件

使用jaybird 2.1.6在blob字段中插入文件
EN

Stack Overflow用户
提问于 2011-06-22 17:08:56
回答 1查看 1.3K关注 0票数 1

我正在尝试使用lib jaybird 2.1.6在Firebird数据库的blob字段中插入一个文件。

首先,我在数据库中创建一条记录,然后使用记录的id,尝试将文件插入到blob (子类型0)字段中。

下面是我的代码:

代码语言:javascript
复制
public static boolean insertBlob(File p_file, String p_maxId) {
    String requette = 
        "UPDATE MAIL_RECU a SET a.CONTENU=? where a.ID_MESSAGE_RECU="+ p_maxId;

    PreparedStatement ps = null;
    FileInputStream input = null;
    try {
        ps = laConnexion.prepareStatement(requette);
        input = new FileInputStream(p_file);

        int paramIdx = 1;
        ps.setBinaryStream(paramIdx++, input, p_file.length());
        ps.executeUpdate();
    } catch (SQLException e) {
        System.out.println("cause: " + e.getCause());
        System.out.println("stacktrace: " + e.getStackTrace());
        System.out.println(e);
        messageUtilisateur.affMessageException(e,
                "Erreur à l'insertion d'un blob");
    } catch (FileNotFoundException e) {
        messageUtilisateur.affMessageException(e,
                "impossible de trouver le fichier");
    } finally {
        try {
            ps.close();
            input.close();

        } catch (SQLException e) {
            messageUtilisateur.affMessageException(e,
                    "Erreur à l'insertion d'un blob");
        } catch (IOException e) {
            messageUtilisateur.affMessageException(e, "fichier non trouvé");

        }
    }

    return true;
}

问题是我有一个例外,当

代码语言:javascript
复制
ps.setBinaryStream(paramIdx++, input, p_file.length());

将被执行。

我收到一条消息"java.sql.SQLException:尚未实现“。我的问题是,有人已经有这个问题了吗?如果是,他(或她)是如何修复它的?有没有其他方法可以用jaybird在blob中存储文件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-22 17:22:58

setBinaryStream(int, InputStream, long)是一种JDBC4 (Java6)方法。

据我所知,Jaybird仍然是JDBC3,所以你需要改用PreparedStatement.setBinaryStream(int, InputStream, int)

代码语言:javascript
复制
ps.setBinaryStream(paramIdx++, input, (int)p_file.length());
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6437473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档