Essentially, you have to insert an empty_lob() first and then get the
binary outputstream for this lob; finally you stream the data to this
output stream..
regards,
Martin
private static Log log = LogFactory.getLog(BlobWrapper.class);
/**
* Creates a new instance of BlobWrapper
*/
public BlobWrapper(Connection connection, String tableName, String
idColumn, String lobColumn)
{
super(connection, tableName, idColumn, lobColumn);
}
/**
* Creates a new instance of BlobWrapper; providing a sequence.
*/
public BlobWrapper(Connection connection, String tableName, String
seqName, String idColumn, String lobColumn)
{
super(connection, tableName, seqName, idColumn, lobColumn);
}
protected String getEmptyLobString()
{
return "empty_blob()";
}
protected void handleLobResultSetForWriting(ResultSet rs,
Object inputStreamOrReader,
String query) throws SQLException
{
if(!(inputStreamOrReader instanceof InputStream))
throw new SQLException("InputStream (and no Reader) must
be provided.");
BLOB blob = null;
if(rs.next())
{
blob = (oracle.sql.BLOB) rs.getBlob(_lobColumn);
}
else
throw new SQLException("BLOB not found");
if(rs.next())
throw new SQLException("BLOB not uniquely identified.");
int size = blob.getBufferSize();
OutputStream outstream = blob.getBinaryOutputStream ();
writeStream((InputStream)
inputStreamOrReader,outstream,size,query.toString());
}
public int getBufferSize(Blob blob)
throws SQLException
{
int bufferSize;
if(blob instanceof BLOB)
{
bufferSize= ((BLOB) blob).getBufferSize();
}
else
{
bufferSize=(int) Math.min(blob.length(),100000);
}
return bufferSize;
}
public void selectFile(String id, String fileName)
{
File binaryFile = new File(fileName);
Blob blob = select(id);
try
{
InputStream instream = blob.getBinaryStream();
OutputStream outstream = new FileOutputStream(binaryFile);
int bufferSize;
bufferSize = getBufferSize(blob);
writeStream(instream,outstream,bufferSize,fileName);
}
catch(SQLException ex)
{
IllegalStateException ex2 =
new IllegalStateException("Reading did not work");
ex2.initCause(ex);
throw ex2;
}
catch(IOException ex)
{
IllegalStateException ex2 =
new IllegalStateException("Writing was not possible");
ex2.initCause(ex);
throw ex2;
}
}
public Blob select(String id)
{
addColumn(_idColumn);
addColumn(_lobColumn);
Statement stmt = null;
ResultSet rs = null;
StringBuffer selectBuf = null;
try
{
stmt = _connection.createStatement();
selectBuf = new StringBuffer();
selectBuf.append("SELECT ");
addColumnNames(selectBuf);
selectBuf.append(" FROM ");
selectBuf.append(_tableName);
selectBuf.append(" WHERE ");
selectBuf.append(_idColumn);
selectBuf.append("=");
selectBuf.append(id);
rs = stmt.executeQuery(selectBuf.toString());
Blob blob = null;
if(rs.next())
{
blob = rs.getBlob(_lobColumn);
getColumnValues(rs);
}
else
throw new SQLException("BLOB not found.
Select-statement : "+selectBuf==null?null:selectBuf.toString());
if(rs.next())
throw new SQLException("BLOB not uniquely identified.
Select-statement : "+selectBuf==null?null:selectBuf.toString());
return blob;
}
catch(SQLException ex)
{
IllegalStateException ex2 =
new IllegalStateException("Writing did not work,
Select-statement : "+selectBuf==null?null:selectBuf.toString());
ex2.initCause(ex);
throw ex2;
}
finally
{
try
{
if(stmt!=null)
stmt.close();
if(rs!=null)
rs.close();
}
catch(SQLException ex)
{
log.error("Exception while closing rs/stmt",ex);
}
}
}
On Thu, 18 Nov 2004 09:52:34 +0100, Nicolas Arni-Bloch
<[EMAIL PROTECTED]> wrote:
> I'm using oracle to with blob and I know this *&%& 4kb limitation,
> can you send the java code and maybe some error ?
> Le 18 nov. 04, � 09:42, Martin Marinschek a �crit :
>
>
>
> > strange... I don't have any problems with file-upload, using it every
> > day...
> >
> > just to tell you: the 4kB restriction in oracle is something you can
> > work around, if need be
> >
> > regards,
> >
> > Martin
> >
> >
> > On Thu, 18 Nov 2004 09:41:21 +0200, Alecsandru Chirosca
> > <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >>
> >> Here are the informations you requested.
> >>
> >>
> >> The 4k limitation to fileupload is due Oracle BLOB handling
> >> limitation.
> >>
> >> Here are the relevant parts of web.xml :
> >> <filter>
> >> <filter-name>multipartFilter</filter-name>
> >>
> >> <filter-
> >> class>net.sourceforge.myfaces.custom.fileupload.MultipartFilter</
> >> filter-class>
> >> <init-param>
> >> <param-name>maxFileSize</param-name>
> >> <param-value>4k</param-value>
> >> <description>limita de upload la fisiere</description>
> >> </init-param>
> >> </filter>
> >> ......
> >> <filter-mapping>
> >> <filter-name>multipartFilter</filter-name>
> >> <url-pattern>*.jsp</url-pattern>
> >> </filter-mapping>
> >>
> >>
> >> and from our jsp page :
> >> .....
> >> <jh:form id="form1" name="form1"
> >> enctype="multipart/form-data">
> >> <jh:panelGrid id="pg1"
> >> cellspacing="0px" columns="1"
> >> styleClass="bodyClass"
> >> columnClasses="bodyTDLeft,bodyTDright">
> >> <jc:facet name="header">
> >> <jh:graphicImage
> >> url="/afiseazaSigla?imagine=#{editorSigla.societatea.id}"
> >> alt="imagine indisponibila"/>
> >> <!-- this is an image display servlet -->
> >> </jc:facet>
> >> <je:inputFileUpload id="aUpload"
> >> value="#{editorSigla.siglaNoua}"
> >> storage="file"
> >> accept="image/*"/>
> >> <jc:facet name="footer">
> >> <jh:commandButton id="trimiteimaginea"
> >> value="trimite" action="#{editorSigla.modifica}"/>
> >> </jc:facet>
> >> </jh:panelGrid>
> >> </jh:form>
> >> .....
> >>
> >>
> >> The problem is that the procedure editorSigla.modifica does not get
> >> called
> >> at all when using multipart/form-data encoding.
> >>
> >>
> >> Best regards,
> >> Alecs
> >>
> >>
> >>
> >> On Wed, 2004-11-17 at 17:58, Nicolas Arni-Bloch wrote:
> >> Are sure that the multipartFilter is enable ? Normally you must
> >> havesome
> >> think like this in your web.xml (and uncommented)
> >>
> >>
> >> <filter>
> >> <filter-name>multipartFilter</filter-name>
> >>
> >> <filter-
> >> class>net.sourceforge.myfaces.custom.fileupload.MultipartFilter</
> >> filter-class>
> >> <init-param>
> >> <param-name>maxFileSize</param-name>
> >> <param-value>10m</param-value>
> >> <description>Set the size limit for uploaded files.
> >> Format: 10 - 10 bytes
> >> 10k - 10 KB
> >> 10m - 10 MB
> >> </description>
> >> </init-param>
> >> </filter>
> >>
> >> and if you doesn't put multipart/form-data in you form it's
> >> normalthat you
> >> have a null value because the multipartFilter is not calledto.
> >>
> >> Le 17 nov. 04, � 16:41, Alecsandru Chirosca a �crit :
> >>
> >>
> >> Hi list,
> >>
> >>
> >> I have a problem width the fileUpload component, when I
> >> usemultipart/form-data my form does noting (the button that connects
> >> tothe
> >> upload() function from my bean does nothing. When I remove
> >> themultipart/form-data encoduing declaration from the h:form element
> >> theupload() function gets called but I hane null value in
> >> theupploadedFile
> >> property.
> >>
> >>
> >> Anyone had this problem?
> >> the page is quite large and includes a lot of HTML code.
> >>
> >> Any ideea will be apreciated.
> >>
> >>
> >> Best regards,
> >> Alecs
> >>
> >> --
> >> Nicolas Arni-Bloch
> >> Groupe MATIS-Bd, Centre Universitaire d'Informatique
> >> 24 rue General-Dufour
> >> CH-1205 Gen�ve
> >> eMail : [EMAIL PROTECTED]
> >> phone : +41 22 379 76 80
> >> fax : +41 22 379 77 80
> >
> >
> --
> Nicolas Arni-Bloch
> Groupe MATIS-Bd, Centre Universitaire d'Informatique
> 24 rue General-Dufour
> CH-1205 Gen�ve
> eMail : [EMAIL PROTECTED]
> phone : +41 22 379 76 80
> fax : +41 22 379 77 80
>
>