Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Blob Problem in Java

Blob Problem in Java

From: <spicar2808_at_my-deja.com>
Date: Fri, 21 Jan 2000 17:00:21 GMT
Message-ID: <86a3ar$8io$1@nnrp1.deja.com>


I have a problem with a blob in servlet, which contains an image. I have a blob in a Table, and I want to display it on a HTML page. I use Weblogic, jdk1.2.2, jdbc20 and oracle8.0.5. The problem is that I want to select the blob in the table. So i try 2 methods : or a select query, or via an integrated procedure.

This is the code for the method with the integrated procedure. The procedure select in the table the blob and return it. There is one parameter : the Blob,which is declare "out".

package cpq;

import java.io.*;
import java.sql.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;
import oracle.jdbc.driver.*;
import weblogic.db.jdbc.*;

public class displayjpg extends HttpServlet {

  public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException//,SQLException   {
    Connection conn=null;
    Statement stmt=null;
    ResultSet rs=null;
    java.sql.Blob myBlob = null;

    res.setContentType("text/html");

    PrintWriter out =res.getWriter();
    out.println("<HTML><HEAD><TITLE> OLA </TITLE></HEAD>");

    try{

	Class.forName("weblogic.jdbc20.pool.Driver").newInstance();
	}
	catch(Exception e){}

    try{
	conn=
DriverManager.getConnection("jdbc20:weblogic:pool:test",null);
	}
	catch(Exception e){out.println("error conn");}

    try{
	stmt = conn.createStatement ();
	}
	catch(Exception e){out.println("error stmt");}

    try
    {
CallableStatement cstmt= null;
cstmt = (CallableStatement)conn.prepareCall("{call P_RETURN_BLOB(?)}"); cstmt.registerOutParameter(1,java.sql.Types.BLOB);
//
//This is here that the servlet doesn't work. the error message =
"java.sql.SQLException: Unknown type: 2004"
//

cstmt.execute();
OutputStream out2=null;
out2=cstmt.getBlob();

//after i treat the Blob to display it

    cstmt.close();
    stmt.close();
    }
    catch (Exception e)
    {

       out.println("erreur : " + e);
    }
  }
}

So How can I do to get a Blob in Java?
Thanks
Stephane

Sent via Deja.com http://www.deja.com/
Before you buy. Received on Fri Jan 21 2000 - 11:00:21 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US