Create Table with Blob Column
create table xx_attachment(fileId Number, file_name VARCHAR2(255),
file_content_type varchar2(100),file_data blob,
CONSTRAINT xx_attach_pk PRIMARY KEY (fileId));
Create EO,VO add it to AM.
Create below variable and accessor inside Managed Bean or Backing Bean.
import org.apache.myfaces.trinidad.model.UploadedFile;
...
private UploadedFile _file;
public UploadedFile getFile() {
return _file;
}
public void setFile(UploadedFile file) {
_file = file;
}
On JSF Page(jspx/jsf) or Page Fragment(jsff)
1)From DataControl unde XxAttachmentVO1 --> Operations --> Drag CreateInsert method and drop as ADF Button. (When you click this Button it creates Blank row).
2)From Common Components drag inputFile(af:inputFile) component and drop on page.
Make sure you put value as #{<yourMangedBean>.file}
<af:inputFile label="Upload File" id="if1"
value="#{<yourMangedBean>.file}"/>
3)From Common Components drag Button and drop after inputFile component.
Write below code on Button action Listner.
<af:commandButton text="Upload" id="cb11"
action="#{<yourManagedBean.uploadAttach}"/>
4)Add Commit action method in Bindings.
5)For Page Form make sure usesUpload property is True.
<af:form id="f1" usesUpload="true">
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.event.PopupFetchEvent;
import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;
import oracle.jbo.Row;
import oracle.jbo.domain.BlobDomain;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import javax.faces.event.ActionEvent;
...
public String uploadAttach() {
// Add event code here...
//BindingContainer bindings = (BindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
UploadedFile myfile = (UploadedFile)this.getFile();
BindingContext bindingctx = BindingContext.getCurrent();
BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
DCBindingContainer bindingsImpl = (DCBindingContainer)bindings;
DCIteratorBinding iter = bindingsImpl.findIteratorBinding("XxAttachmentVO1Iterator");
Row row = iter.getCurrentRow();
// Upload File into Blob Column
row.setAttribute("FileData", createBlobDomain(myfile));
// File Name
String fileName = (String)myfile.getFilename();
row.setAttribute("FileName", fileName);
// File Content/MIME Type
String fileContentType = (String)myfile.getContentType();
row.setAttribute("FileContentType", fileContentType);
//Commit Transaction
OperationBinding method = bindings.getOperationBinding("Commit");
method.execute();
return null;
}
private BlobDomain createBlobDomain(UploadedFile file) {
InputStream in = null;
BlobDomain blobDomain = null;
OutputStream out = null;
try {
in = file.getInputStream();
blobDomain = new BlobDomain();
out = blobDomain.getBinaryOutputStream();
byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
out.write(buffer, 0, bytesRead);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.fillInStackTrace();
}
return blobDomain;
}
To download file.
http://hasamali.blogspot.com/2011/09/download-file-in-oracle-adf-gui.html
i get tis error can u help me out
ReplyDeletejava.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
Hi Suresh,
ReplyDeleteAre you using LONG column or BLOB column in database ?
Here in above example we used BLOB column and BlobDomain to set attribute.
Thanks,
Jit
Core java is vital for java so as to being utilized in any java generation without this no one can jump on any decorate java era. in which as enhance java is specialization in a few place, which incorporates networking, the internet, com or database dealing with.
ReplyDeletethank regard
Oracle Fusion procurement Coaching Center
Oracle Fusion cloud procurement Online Training