Bonjour,

je souhaiterais charger d'un bloc un fichier XML dans un BLOB.

Existe t-il un moyen d'opérer "en force" par un simple chargement de l'un dans l'autre?

Je ne trouve que cela :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
     * Set a blob into a OraclePreparedStatement.
     * @param st The statement instanceof OraclePreparedStatement
     * @param content The blob content
     * @param index The index of the blob in the sql expression.
     * @throws SQLException If an error occurs while setting blob.
     */
    public static void prepareStatementOracleBlob(PreparedStatement st, byte[] content, int index) throws SQLException{
        if (content == null) {
            st.setNull(index, Types.BINARY);
        } else if (st instanceof oracle.jdbc.OraclePreparedStatement) {
            oracle.jdbc.OraclePreparedStatement ost = (oracle.jdbc.OraclePreparedStatement) st;
            oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st
                    .getConnection(), false, oracle.sql.BLOB.DURATION_SESSION);
            blob.open(oracle.sql.BLOB.MODE_READWRITE);
            OutputStream out = blob.getBinaryOutputStream();
            try {
                out.write((byte[]) content);
                out.flush();
                out.close();
            } catch (IOException e) {
                throw new SQLException("Failed write to blob " + e.getMessage());
            }
            blob.close();
 
            ost.setBLOB(
                    index,
                    blob);
 
        } else
            throw new InvalidParameterException("The prepared statement is not an instance of oracle.jdbc.OraclePreparedStatement, it is a " + st.getClass());
    }
Merci beaucoup et bonne journée.

Sherkaan