Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

storing binary files in blob fields from a servet

  Asked By: Jaxson    Date: Sep 26    Category: Java    Views: 1214
  

I'm working with servlets (jsp) under weblogic 6 and using oracle
8i database and I got a mysterious problem...

i'm doing a form that the user will give some data and a photo
(multipart form data) that will be sent to a servlet that will put
all this in the database.
no problem with the character fields, but when I try to send a file
greater than 4kb, I receive a SQLException for "broken pipe" or "no
more data to be read"
follow the stack trace
java.sql.SQLException: Io exception: Broken pipe
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:168)
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:210)
at oracle.jdbc.dbaccess.DBError.throwSqlException
(DBError.java:323)
at oracle.jdbc.driver.OracleStatement.executeNonQuery
(OracleStatement.java:1460)
at oracle.jdbc.driver.OracleStatement.doExecuteOther
(OracleStatement.java:1371)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout
(OracleStatement.java:1900)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate
(OraclePreparedStatement.java:363)
at weblogic.jdbc.pool.Statement.executeUpdate
(Statement.java:293)
at
weblogic.jdbc.rmi.internal.PreparedStatementImpl.executeUpdate
(PreparedStatementImpl.java:66)
at weblogic.jdbc.rmi.SerialPreparedStatement.executeUpdate
(SerialPreparedStatement.java:57)
at
jsp_servlet._portal._administrativo._portal._admin._contatoscomerciais
.__incluir_cont2._jspService(__incluir_cont2.java:202)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet
(ServletStubImpl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet
(ServletStubImpl.java:200)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet
(WebAppServletContext.java:2546)
at weblogic.servlet.internal.ServletRequestImpl.execute
(ServletRequestImpl.java:2260)
at weblogic.kernel.ExecuteThread.execute
(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
the code follows:
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
//pegando o arquivo como um array de bytes
byte bFoto[] = new byte[mySmartUpload.getFiles().getFile(0).getSize
()];
for(int i=0; i<mySmartUpload.getFiles().getFile(0).getSize(); i++)
{
bFoto[i] = mySmartUpload.getFiles().getFile(0).getBinaryData
(i);
}

//fazendo a inclusão do contato comercial no banco
String sSql ="";
sSql = "insert into testeblob (id, foto) values
(SEQ_CONTATO_COMERCIAL.NEXTVAL, ?)";
out.println(sSql);
PreparedStatement psFoto=oSql.getConexao().prepareStatement(sSql);
java.io.ByteArrayInputStream isFoto = new java.io.ByteArrayInputStream
(bFoto);
try {
psFoto.setBytes(1,bFoto);
//psFoto.setBinaryStream(1,isFoto, bFoto.length );
}
catch(Exception e)
{
out.println("ocorreu um erro(1):"+e.getMessage());
return;
}

psFoto.executeUpdate();


it works perfectly if the file is smaller than 4Kb

Does anyone have an idea of what's happening?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on storing binary files in blob fields from a servet Or get search suggestion and latest updates.




Tagged: