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

5
  • Have a look at this question. It explains how to insert a Blob in oracle db via jdbc Commented Dec 2, 2016 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. Commented Dec 2, 2016 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 Commented Dec 2, 2016 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 Commented Dec 2, 2016 at 18:07
  • did you figure out a way to save it using standard vertx operations? Commented Jun 8, 2017 at 8:27

1 Answer 1

2

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");
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.