Hello All,
I have a requirement to upload csv files into BLOB columns in Oracle DB. Users will be shown two input file components where they can select only csv files(one in each inputFile component). Once the files are selected, I am using IOUtils API from Apache Commons to copy the InputStream from those files to respective OutputStream of new BlobDomain object so I can insert into DB.
InputStream in = null;
BlobDomain blobDomain = null;
OutputStream out = null;
try {
in = file.getInputStream();
blobDomain = new BlobDomain();
out = blobDomain.getBinaryOutputStream();
IOUtils.copy(in, out);
}
I pass this data along with other required data of the respective files to the model project AMImpl method (using custom SelectedFile model object having metadata in a List object passed to AMImpl method) to insert into the DB. I am using EO based VO to create new rows and update the Blob column of the DB field using the below code - FileContent column here is the BLOB column.
for(int i = 0; i < uploadFiles.size(); i++) {
uploadFile = (SelectedFile) uploadFiles.get(i);
Row newRow = portalFilesVO.createRow();
newRow.setAttribute("FileSequence", nextPortalFileSeq);
newRow.setAttribute("FileType", uploadFile.getFileType());
newRow.setAttribute("Filename", uploadFile.getFileName());
newRow.setAttribute("FileContent", uploadFile.getFileBlob());
portalFilesVO.insertRow(newRow);
}
this.getDBTransaction().commit();
It does insert the data in the new rows in the view object. However, when the commit operation is executed, it is throwing the following error -
oracle.jbo.DMLException: JBO-26041: Failed to post data to database during "Insert": SQL Statement "JBO-29000: Unexpected exception caught: java.sql.SQLRecoverableException, msg=IO Error: An existing connection was forcibly closed by the remote host".
at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:9769)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:9619)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:7488)
at oracle.jbo.server.EntityImpl.callPostChanges(EntityImpl.java:7267)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3390)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:3183)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2181)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2461)
at gov.tn.tccms.operations.model.module.TCCMSOperationsAMImpl.processUploadedFiles(TCCMSOperationsAMImpl.java:399)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.sql.SQLRecoverableException, msg=IO Error: An existing connection was forcibly closed by the remote host
at oracle.jbo.domain.BlobDomain.writeBytesToLob(BlobDomain.java:464)
at oracle.jbo.domain.BaseLobDomain.saveToDatabase(BaseLobDomain.java:624)
at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:9740)
... 107 more
Caused by: java.sql.SQLRecoverableException: IO Error: An existing connection was forcibly closed by the remote host
at oracle.jdbc.driver.T4CConnection.putBytes(T4CConnection.java:3097)
at oracle.sql.BLOB.setBytes(BLOB.java:803)
at weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB.setBytes(Unknown Source)
at oracle.jbo.domain.BlobDomain.writeBytesToLob(BlobDomain.java:459)
... 109 more
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
## Detail 0 ##
oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.sql.SQLRecoverableException, msg=IO Error: An existing connection was forcibly closed by the remote host
at oracle.jbo.domain.BlobDomain.writeBytesToLob(BlobDomain.java:464)
at oracle.jbo.domain.BaseLobDomain.saveToDatabase(BaseLobDomain.java:624)
at oracle.jbo.server.EntityImpl.doDMLWithLOBs(EntityImpl.java:9740)
at oracle.jbo.server.EntityImpl.doDML(EntityImpl.java:9619)
at oracle.jbo.server.EntityImpl.postChanges(EntityImpl.java:7488)
at oracle.jbo.server.EntityImpl.callPostChanges(EntityImpl.java:7267)
at oracle.jbo.server.DBTransactionImpl.doPostTransactionListeners(DBTransactionImpl.java:3390)
at oracle.jbo.server.DBTransactionImpl.postChanges(DBTransactionImpl.java:3183)
at oracle.jbo.server.DBTransactionImpl.commitInternal(DBTransactionImpl.java:2181)
at oracle.jbo.server.DBTransactionImpl.commit(DBTransactionImpl.java:2461)
at gov.tn.tccms.operations.model.module.TCCMSOperationsAMImpl.processUploadedFiles(TCCMSOperationsAMImpl.java:399)
Can someone please highlight any idea why this error is thrown when I am trying to commit the data? Any help is appreciated. Thank you in advance.
Note: We did test the same piece of code with several csv files. It did work for several files so I know it is not because of data. However, this is only happening with certain files. Most of the files are around ~1.5 MB. Another thing to notice is that when we open the csv file(for which it is failing) and maximize all the columns(Click on top left column which selects all the data in csv and double click between the header columns) to display column data properly, save and try to upload that file, it will be uploaded. However, after maximizing all the columns if we add any new rows and try to upload that file, it fails to upload same as with the above error. Somehow it shows existing DBConnection is being closed abruptly.
We are using Oracle JDeveloper 12.2.1.3.0, Oracle DB 12c, Weblogic Server 12.2.1.3.0
Thanks,
Mahesh