• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

interesting question

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}
}
 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic