wood burning stoves 2.0*
The moose likes Websphere and the fly likes interesting question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "interesting question" Watch "interesting question" New topic
Author

interesting question

daman sidhu
Ranch Hand

Joined: Aug 19, 2000
Posts: 184
Hi Guys,
I have a situation, hope you might be able to help me out, though this is not very particular to WAS.
I have a table in oracle in which i store a picture file as a blob object, i use an EJB which takes a byte stream as an argument for the same column. NOw i have to create a administrative GUI by which the user will be able to upload the picture and provide information for the other columns also.THe form will have a browse button for the file selection and corresponding upload, but for this the form send multipart data and i will have to use a datainputstream to read it, which will now contain both the image file as well as other table related information.How will i be able to seperate the content from one another ie the file from the other fields the user fills in because using the multipart data wont allow the normal request.getParameter syntax.And i cannot submit 2 different forms as another option because i need the other info user submits to get the handle on that row.
Lookin forward to your response.
Regards.
Daman
ramdas nayak
Greenhorn

Joined: Jul 13, 2001
Posts: 8
this servlet has been tested for retreiving Blob datatype for image file form DB2 Database.Kindly convert it for oracle database wherevere needed thanx.
package test;
/**
* Insert the type's description here.
* Creation date: (1/23/99 11:36:37 PM)
* @author: Administrator
*/
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BlobServlet extends javax.servlet.http.HttpServlet
{
Connection con= null;
Statement stmt= null;
ResultSetrs= null;
/**
* Process incoming HTTP GET requests
*
* @param request Object that encapsulates the request to the servlet
* @param response Object that encapsulates the response from the servlet
*/
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
{
performTask(request, response);
}
/**
* Process incoming HTTP POST requests
*
* @param request Object that encapsulates the request to the servlet
* @param response Object that encapsulates the response from the servlet
*/
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
/**
* Returns the servlet info string.
*/
public String getServletInfo() {
return super.getServletInfo();
}
/**
* Initializes the servlet.
*/
public void init() {
// insert code to initialize the servlet here
}
/**
* Process incoming requests for information
*
* @param request Object that encapsulates the request to the servlet
* @param response Object that encapsulates the response from the servlet
*/
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
{
try
{
// I have tested this servlet for my application change to make it general

//change here to remove hard coding of the sql query
String rSQL="select * from BlobTest where row_id='12'";
//change database driver and url etc.

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
con=DriverManager.getConnection("jdbc:db2:SAMPLE","db2admin","udbadmin");
stmt=con.createStatement();
rs=stmt.executeQuery(rSQL);
//if no O/p found then just display message on the browser

if(! rs.next())
{
response.setContentType("text/html");
PrintWriter pout= new PrintWriter(response.getOutputStream());
pout.println("No Matching records found ");
pout.flush();
pout.close();

}//if(! rs.next())
// for reading the message set this .
response.setContentType("image/gif");
ServletOutputStream out= response.getOutputStream();
InputStream in=rs.getBinaryStream(2);
ByteArrayOutputStream baos= new ByteArrayOutputStream();
byte b[]= new byte[1024];
while(true)
{
int bytes=in.read(b);

if(bytes == -1)
{
break;
}//if
baos.write(b,0,bytes);
}//while
b=baos.toByteArray();
response.setContentLength(b.length);
out.write(b,0,b.length);
out.flush();
out.close();
System.out.println("successful");

}//try
catch(Throwable theException)
{
response.setContentType("text/html");
PrintWriter pout= new PrintWriter(response.getOutputStream());
pout.println("Exception while retreiving");
pout.flush();
pout.close();

}
finally
{
try
{

if(stmt != null) stmt.close();
if(rs != null) rs.close();
if(con != null) con.close();

}//try
catch(Exception ex)
{

}//catch
}//finally
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: interesting question
 
Similar Threads
Clarrification about HttpServletRequest
suggestions wanted
file upload in servlet?
problem with multipart/form-data
How to get the request parameters while the enctype is multipart/form-data