0

I'm trying to insert BLob into Oracle database using vert.x, i get the upload File

     for (FileUpload f : routingContext.fileUploads()){
         System.out.println("file name " + f.fileName());
         System.out.println("size name " + f.size());
         System.out.println("Uploaded File " + f.uploadedFileName());
     }

I have converted FileUpload to bytes Array by using :

 Buffer fileUploaded = routingContext.vertx().fileSystem().readFileBlocking(f.uploadedFileName());

 byte[] fileUploadedBytes = fileUploaded.getBytes();

Now I want to insert it directly to the Oracle database, i have tried to use updateWithParams, but i don't know how to add Blob into the query params. thank you for your help

OLH
  • 194
  • 3
  • 12
  • Have a look at this [question](http://stackoverflow.com/questions/8348427/how-to-write-update-oracle-blob-in-a-reliable-way). It explains how to insert a Blob in oracle db via jdbc – ZeusNet Dec 02 '16 at 16:40
  • thank you @ZeusNet for your answer, but i'm using `JDBCClient Vertx`, so I have to use `queryWithParams` to create a `preparedStatement` then I can't call `setBinaryStream`. – OLH Dec 02 '16 at 17:43
  • But you could probably wrap the bytes of the file into the JsonArray? I'm not familiar with vert.x but I would give it a try – ZeusNet Dec 02 '16 at 17:49
  • yes i have tried to use it and i get this error `ORA-01461: can bind a LONG value only for insert into a LONG column`, by the way i have a Blob column in the dataBase – OLH Dec 02 '16 at 18:07
  • did you figure out a way to save it using standard vertx operations? – Markus Jun 08 '17 at 08:27

1 Answers1

1

this is my implementation to resolve my problem , now I can insert file Blob into the Oracle dataBase, I hope that will help someone in the future.

 ByteArrayInputStream finalBis = bis;
    byte[] finalFileUploadedBytes = fileUploadedBytes;
    DB.getConnection(connection -> {
        if (connection.succeeded()) {
            CallableStatement stmt = null;
            try {
                stmt = connection.result().getConnection().prepareCall(SQL.INSERT_DOCS_QUERY);
                stmt.setBinaryStream(1, finalBis, finalFileUploadedBytes.length);
                stmt.setString(2,desiDoc);
                stmt.setString(3,sourDoc);
                logger.debug(stmt);
                stmt.execute();
                finalBis.close();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("nooot  ok");
        }
    });
OLH
  • 194
  • 3
  • 12