开发者

Insert file in blob field with jaybird 2.1.6

I'm trying to insert a file in a blob field in a Firebird database using lib jaybird 2.1.6.

First, I create a record in my database, then, with the id of record, I try to insert my file in a blob (subtype 0) field.

Here is my code:

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;
}

The problem is I have an exception when

ps.setBinaryStream(paramIdx++, input, p_file.length());

is executed.

I have a message "java.sql.SQLException: not yet implemented". My question is, is anyone have already have this problem? If yes, how did he (or she) fix it? Is there another way to store file in blob with jaybird?


setBinaryStream(int, InputStream, long) is a JDBC4 (Java 6) method.

As far as I know Jaybird is still JDBC3, so you need to use PreparedStatement.setBinaryStream(int, InputStream, int) instead:

ps.setBinaryStream(paramIdx++, input, (int)p_file.length());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜