Hi
I have a JSP file where user can upload files to the server. This JSP calls a servlet which does the uploading, after the file is uploaded I call EJB which inerserts the file in to Database. The problem is I there is no exception or error but the file is not insertred in the database.
The EJB method is like this.
public boolean insertTemplate (String ,java.io.InputStream oData,String sName)
{
makeConnection();//Open Connection to database
int update = 0;
try {
con.setAutoCommit(false);
sql ="insert into HTML_TEMPLATE values(HTML_TEMPLATE_SEQ.nextval,'" + sName + "',EMPTY_BLOB(),'" + sPid + "')";
update = stm.executeUpdate(sql);
java.sql.Blob myBlob = null;
Statement stmt2 = con.createStatement();
stmt2.execute("SELECT TEMPLATE from HTML_TEMPLATE");
ResultSet rs = stmt2.getResultSet();
while (rs.next())
{
myBlob = rs.getBlob("TEMPLATE");
}
java.io.InputStream is = oData;
System.out.println("The InputStream in EJB is :" + is);
java.io.OutputStream os = ((weblogic.jdbc.common.OracleBlob) myBlob).getBinaryOutputStream();
byte[] inBytes = new byte[65534];
int numBytes = is.read(inBytes);
while (numBytes > 0)
{
os.write(inBytes, 0, numBytes);
numBytes = is.read(inBytes);
}
//Clean up
os.write(inBytes);
os.flush();
os.close();
stmt2.close();
} catch (Exception e) {
System.out.println("EJB - An exception has been raised during the insertion of the Template details" + e.getMessage());
}
finally
{
try
{
con.commit();
closeConnection();
}
catch(Exception ex)
{
ex.toString();
}
}
if(update == 0)
{
return false;
}
else
{
return true;
}
} //End of insert template method
Please help me with this.
ThankYou
Asad
-
Writing to BLOB (5 messages)
- Posted by: Asad Aziz
- Posted on: June 08 2001 13:16 EDT
Threaded Messages (5)
- Writing to BLOB by Eric Ma on June 08 2001 23:58 EDT
- Writing to BLOB by Asad Aziz on June 11 2001 11:36 EDT
-
Writing to BLOB by Eric Ma on June 11 2001 10:05 EDT
- Writing to BLOB by Asad Aziz on June 12 2001 02:35 EDT
- Re: Writing to BLOB by Upeksha Dharma on September 05 2007 08:42 EDT
-
Writing to BLOB by Eric Ma on June 11 2001 10:05 EDT
- Writing to BLOB by Asad Aziz on June 11 2001 11:36 EDT
-
Writing to BLOB[ Go to top ]
- Posted by: Eric Ma
- Posted on: June 08 2001 23:58 EDT
- in response to Asad Aziz
Make sure the TX attribute of your EJB method is REQUIRED. -
Writing to BLOB[ Go to top ]
- Posted by: Asad Aziz
- Posted on: June 11 2001 11:36 EDT
- in response to Eric Ma
ThankYou for your reply
The Transaction is REQUIRED in the EJB but, I dont know where I am doing wrong. I cannot insert the files in the database. What am I missing in the code?
Asad
-
Writing to BLOB[ Go to top ]
- Posted by: Eric Ma
- Posted on: June 11 2001 22:05 EDT
- in response to Asad Aziz
I would do the following:
1. Change the following line to
stmt2.execute("SELECT TEMPLATE from HTML_TEMPLATE FOR UPDATE");
2. Remove the transaction management code such as con.setAutoCommit(false) and con.commit and let the EJB container take care of it. -
Writing to BLOB[ Go to top ]
- Posted by: Asad Aziz
- Posted on: June 12 2001 14:35 EDT
- in response to Eric Ma
Thanks Eric
I removed the two lines, the transaction code and now its working. Thankyou for yr help
Bye
Asad
-
Re: Writing to BLOB[ Go to top ]
- Posted by: Upeksha Dharma
- Posted on: September 05 2007 08:42 EDT
- in response to Eric Ma
Hi, I Have a probelm of getting data as a stream. When i try the above code system just hangs. My need is to store image files in a database column. Thanks in advance