Bonjour,
Je cherche à dupliquer 1 champ Oracle du type LONG RAW de manière "automatique".
Ne pouvant pas le faire directement en SQL (limitation des champs LONG RAW) et étant limité à 32Ko pour les variables PL/SQL (j'ai au minimum 400Ko de données à copier), j'ai écris le programme java suivant:
La méthode appelée est updateTheLongRaw à qui je passe les références source et cible.Code:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 import java.sql.*; import oracle.jdbc.driver.*; import java.io.*; public class GetLongRawField { public static byte[] getTheLongRaw (int projID, Connection conn) { byte[] myLongRaw = null; try{ System.out.println("java: start selecting long raw field"); String query = "SELECT reserved_binary_data FROM TEST_TABLE WHERE proj_id="+ projID; PreparedStatement pst = conn.prepareStatement(query); ResultSet result = pst.executeQuery(); if(result.next()){ myLongRaw = result.getBytes(1); System.out.println("java: get first line data"); System.out.println(myLongRaw.length); } } catch (Exception ex){ System.err.println("ERROR!: " + ex.getMessage()); ex.printStackTrace(); } return myLongRaw; } public static void updateTheLongRaw (int oldProj, int newProj){ try{ Connection conn = new OracleDriver().defaultConnection(); // DriverManager.registerDriver(new OracleDriver()); // Connection conn = DriverManager.getConnection("jdbc:oracle:kprb:"); byte[] test = getTheLongRaw(oldProj, conn); ByteArrayInputStream myNewLongRaw = new ByteArrayInputStream(test); System.out.println("java: start duplicating long raw field"); String query = "UPDATE TEST_TABLE SET reserved_binary_data = ? WHERE proj_id=" + newProj; PreparedStatement pst = conn.prepareStatement(query); pst.setBinaryStream(1, myNewLongRaw, test.length); pst.executeUpdate(); System.out.println("java: done duplicating long raw field"); } catch (Exception ex){ System.err.println("ERROR!: " + ex.getMessage()); ex.printStackTrace(); } } }
Cette méthode est "encapsulée" dans une procédure PL/SQL utilisée par un trigger Oracle.
La duplication fonctionne bien, sauf que je ne copie que 32Ko (et non les 400Ko espéré).
Une idée de la raison de ce problème?
est-ce un problème de driver? si oui, lequel dois-je utiliser?
merci d'avance.