1

lib jaybird 2.1.6を使用して、Firebirdデータベースのblobフィールドにファイルを挿入しようとしています。

まず、データベースにレコードを作成し、次にrecordのIDを使用して、ファイルをblob(サブタイプ0)フィールドに挿入しようとします。

これが私のコードです:

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

問題は、例外がある場合です

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

実行されます。

「java.sql.SQLException:まだ実装されていません」というメッセージが表示されます。私の質問は、誰かがすでにこの問題を抱えているのですか?はいの場合、彼(または彼女)はどのようにそれを修正しましたか?jaybirdを使用してファイルをblobに保存する別の方法はありますか?

4

1 に答える 1

2

setBinaryStream(int, InputStream, long)JDBC4(Java 6)メソッドです。

私の知る限り、JaybirdはまだJDBC3なので、PreparedStatement.setBinaryStream(int, InputStream, int)代わりに次のものを使用する必要があります。

ps.setBinaryStream(paramIdx++, input, (int)p_file.length());
于 2011-06-22T09:22:57.997 に答える