Reputation: 204
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
Upvotes: 0
Views: 797
Reputation: 204
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");
}
});
Upvotes: 2