Convert BLOB from database to XML. - *URGENT*

Hi,
I have converted xml data into BLOB object and inserted into database.
Now when I retrieve the BLOB object,from my DB, using DBadapter, in the invokeOutputVariable, i have the following. This i copied from the 'Flow Trace'
<Invoke1_GetSourceXML_OutputVariable>
<part name="GetSourceXMLOutputCollection" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<GetSourceXMLOutputCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/GetSourceXML">
<GetSourceXMLOutput>
<INSTANCE_ID>1</INSTANCE_ID>
*<SOURCE_XML>weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB@78f9a</SOURCE_XML>*
<TARGET_XML xsi:nil="true"/>
<ORDER_ID>1</ORDER_ID>
<TASK_INSTANCE_ID>1</TASK_INSTANCE_ID>
<ORDER_DATE xsi:nil="true"/>
<TRANSLATION_TYP_CD xsi:nil="true"/>
<EBM_ID>1</EBM_ID>
<STATUS xsi:nil="true"/>
<STATUS_DETAIL xsi:nil="true"/>
</GetSourceXMLOutput>
</GetSourceXMLOutputCollection>
</part>
</Invoke1_GetSourceXML_OutputVariable>
1) Here i want to confirm, whether we l get weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB@78f9a sort of value when we retrieve a BLOB object.
2) Variable declaration is like below.
<variable name="binaryXML" type="xsd:string"/>
<variable name="decodedString" type="xsd:string"/>
binaryXML - value assignment_
<assign name="Assign2">
<copy>
<from variable="Invoke1_GetSourceXML_OutputVariable"
part="GetSourceXMLOutputCollection"
query="/ns2:GetSourceXMLOutputCollection/ns2:GetSourceXMLOutput/ns2:*SOURCE_XML*"/>
<to variable="binaryXML"/>
</copy>
</assign>
I have written java embedding code for converting this BLOB to  xml as below
String input = (String)getVariableData("binaryXML");
try
/* *** INITIALLY I TRIED LIKE THIS*** */
//byte[] decodedBytes = Base64Decoder.decode(input.getBytes());
//String decoded = new String(decodedBytes);
//setVariableData("decodedString",decoded);
/* *** MY NEW CODE *** /
String decoded = Base64Decoder.decode(input);
setVariableData("decodedString",decoded);
catch(Exception ex)
ex.printStackTrace();
My Doubt
When I try to write this 'decodedString' to a .txt file, I couldnt find any output there.
<assign name="Assign3">
<copy>
<from variable="decodedString"/>
<to variable="Invoke2_Write_InputVariable" part="body"
query="/ns4:Root/ns4:C1"/>
</copy>
</assign>
Regarding the schema for the file to be written, i tried with 'opaque' schema.. I dint work. Later i tried with the schema as below (which is comma delimited)
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
xmlns:tns="http://TargetNamespace.com/WriteToFile"
targetNamespace="http://TargetNamespace.com/WriteToFile"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
nxsd:version="NXSD"
nxsd:stream="chars"
nxsd:encoding="US-ASCII"
>
<xsd:element name="Root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C1" type="xsd:string" nxsd:style="terminated" nxsd:terminatedBy="," nxsd:quotedBy="&quot;" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Kindly help me in ths regard.
Thanks,
Sabarisri. N
Edited by: Sabarisri N on Jul 22, 2011 2:37 PM

Read this :
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14252/adx_j_xsu.htm#sthref508

Similar Messages

  • Convert BLOB from database to string

    Hi All,
    I have retrieved the blob data from my database , and now i have it in my InvokeVariable. The below details will brief the structure of my output variable.
    <variable name="Invoke1_RetrieveRecordForInstanceId_OutputVariable"
    messageType="*ns1:RetrieveRecordForInstanceIdOutputCollection_msg*"/>
    <wsdl:message name="RetrieveRecordForInstanceIdOutputCollection_msg">
    <wsdl:part name="RetrieveRecordForInstanceIdOutputCollection" element="db:RetrieveRecordForInstanceIdOutputCollection"/>
    </wsdl:message>
    <xs:complexType name="RetrieveRecordForInstanceIdOutputCollection">
    <xs:sequence>
    <xs:element name="RetrieveRecordForInstanceIdOutput" type="RetrieveRecordForInstanceIdOutput" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="RetrieveRecordForInstanceIdOutput">
    <xs:sequence>
    <xs:element name="INSTANCE_ID" type="xs:decimal" nillable="true"/>
    <xs:element name="SOURCE_XML" type="xs:base64Binary" nillable="true"/>
    <xs:element name="TARGET_XML" type="xs:base64Binary" nillable="true"/>
    </xs:sequence>
    </xs:complexType>
    I make my assign statement like below.
    <assign name="Assign2">
    <copy>
    <from variable="Invoke1_RetrieveRecordForInstanceId_OutputVariable"
    part="RetrieveRecordForInstanceIdOutputCollection"
    query="/ns2:RetrieveRecordForInstanceIdOutputCollection/ns2:RetrieveRecordForInstanceIdOutput/ns2:SOURCE_XML"/>
    <to variable="EnhancedBLOBdata"/>
    </copy>
    </assign>
    I have my java code for converting the blob to string as below.
    String input = (String)getVariableData("*EnhancedBLOBdata*");
    Base64Decoder baseDecoder= new Base64Decoder();
    try {            
    byte[] decodedBytes = input.getBytes();
    String decoded = new String(decodedBytes);
    //String decoded = Base64Decoder.decode(input);
    setVariableData("DecodedString", decoded);
    catch(Exception ex)
    ex.printStackTrace();
    The data type of EnhancedBLOBdata is base64Binary.. I also checked with 'string' . Even then i dint get the proper decoded form.
    Can anyone help me in using the variable SOURCE_XML coming under the RetrieveRecordForInstanceIdOutputCollection, directly in the line,
    String input = (String)getVariableData("*Invoke_Output_Variable....<some format>*");
    so that there is no need of assigning to some other variable.. Bcz while assignig i am not sure, the assigned variable contains data in blob format.
    Kindly help me in this regard.
    Thanks,
    Sabarisri. N

    I have figured out the error happens on a data picture with about 700KB of data all of the other data fields have less than 100KB. Is there a way around this size issue.

  • Issue to load data from database to XML file. error: ODI-40768

    Hi,
    While I am trying to load data from database to XML following error is appearing.
    ODI-1228: Task TEST_XML_DATA (Integration) fails on the target XML connection MyLOCALXSD.
    Caused By: java.sql.SQLException: ODI-40768: Could not save the file <default>:C:\DATA_FILE\www.xml because a class java.io.IOException occurred and said: The filename, directory name, or volume label syntax is incorrect
         at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.writeToFile(SnpsXmlFile.java:751)
         at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.internalExecute(SnpsXmlConnection.java:769)
         at com.sunopsis.jdbc.driver.xml.SnpsXmlPreparedStatement.execute(SnpsXmlPreparedStatement.java:46)
         at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:166)
         at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
         at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
         at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:540)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:338)
         at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:263)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:822)
         at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
         at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:83)
         at java.lang.Thread.run(Thread.java:662)
    jdbc url: jdbc:snps:xml?d=C:\test_xsd.xsd&s=TESTSQL&re=employeesX&ro=true
    physical schema: TESTSQL
    Knowledge modules are:
    LKM: LKM SQL to SQL
    IKM: IKM XML Control Append
    CKM: CKM SQL
    Parameters set are:
    CREATE_XML_FILE: true
    XML_PATH:<default>:C:\DATA_FILE\www.xml
    I have tried to change the directory path but error is still there.
    Could some one please help me to resolve the issue?
    Regards,
    user1672911

    Hi,
    The trouble in "<default>:"  - if you set XML_PATH as C:\DATA_FILE\www.xml instead  <default>:C:\DATA_FILE\www.xml- it will work correctly.
    Greetings,
    Eugene

  • How to write from database to XML file using JAVA and back..

    Hi....
    I am strugling for a code to write from database to xml output instead of what i have written in flat file....could anyone please help me out...to do this and again read the same back to the database using java...

    Hi,
    In java world, there is a tutorial on what you are looking for :
    http://www.javaworld.com/javaworld/jw-01-2000/jw-01-dbxml_p.html
    It uses SAX/DOM parsers to translate XML data into the appropriate fields of the database and visa-versa.
    Hope it helps.

  • Export Advanced Recordset from Database into XML

    I don't think I was clear on my previous post about my goal
    with Exporting an advanced MySQL query to an XML file.
    Simple example: I have a photo gallery that has pictures of
    various Architect Projects. The main page shows distinct images of
    various projects (like an index). When one clicks on this image to
    view the rest of the Project details, a detail page opens with more
    information and additional images within this project.
    I want to use Spry/Ajax to give the images nice dynamic
    effects on the detail page. Normally to get from an index page to a
    detail page using normal server-side procedures, one would have to
    set up a dynamic link to the detail page by passing the recordID
    thru a URL Parameter. The detail page would have a recordset query
    that would call the URL Parameter so that the distinct record
    chosen will be the only record displayed.
    When exporting this query from the database to XML, for some
    reason the following query only displays the <row> node in
    the schema when creating a Dataset. See the following sql query
    that I am trying to use on the detail page to create the dataset
    via XML:
    SELECT*
    FROM project_tbl
    WHERE projectID = [URL PARAM] projectID
    Why, when creating a dataset in Spry and exporting it into
    XML, will this query NOT work?
    What can I do to make this work? URGENT HELP will be kindly
    appreciated.

    Danilo,
    I do not have a link yet as the files are on my remote
    server. I have implemented the code you sent me but still no luck.
    Please see the code I have below:
    The XML Generating Page:
    <?php require_once('../Connections/plymouth.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType,
    $theDefinedValue = "", $theNotDefinedValue = "")
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue)
    : $theValue;
    $theValue = function_exists("mysql_real_escape_string") ?
    mysql_real_escape_string($theValue) :
    mysql_escape_string($theValue);
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theValue) .
    "'" : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" :
    "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue :
    $theNotDefinedValue;
    break;
    return $theValue;
    ?>
    <?php
    // Query the database and get the selected records from
    Project & Images
    $colname_rsProject = "-1";
    if (isset($_GET['projectID'])) {
    $colname_rsProject = (get_magic_quotes_gpc()) ?
    $_GET['projectID'] : addslashes($_GET['projectID']);
    mysql_select_db($database_plymouth, $plymouth);
    $query_rsProject = sprintf("SELECT * FROM projects_tbl WHERE
    projectID = %s", GetSQLValueString($colname_rsProject, "int"));
    $rsProject = mysql_query($query_rsProject, $plymouth) or
    die(mysql_error());
    $row_rsProject = mysql_fetch_assoc($rsProject);
    $totalRows_rsProject = mysql_num_rows($rsProject);
    // Send the headers
    header('Content-type: text/xml');
    header('Pragma: public');
    header('Cache-control: private');
    header('Expires: -1');
    ?>
    <?php echo('<?xml version="1.0"
    encoding="utf-8"?>'); ?>
    <root>
    <?php if ($totalRows_rsProject > 0) { // Show if
    recordset not empty ?>
    <?php do { ?>
    <row>
    <?php foreach ($row_rsProject as $column=>$value) {
    ?>
    <<?php echo $column; ?>><?php echo
    $row_rsProject[$column]; ?></<?php echo $column; ?>>
    <?php } ?>
    </row>
    <?php } while ($row_rsProject =
    mysql_fetch_assoc($rsProject)); ?>
    <?php } // Show if recordset not empty ?>
    </root>
    <?php
    mysql_free_result($rsProject);
    ?>
    --------------------------------------------here is the
    source code to the projecct_detail page to display the
    content--------
    The projectID from the category page is being passed via a
    URL parameter. When I pull up the Spry Dataset in this page to
    display the nodes, this is the error I received (Unable to locate
    or parse the XML source (-1,-1). No nodes are being displayed.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml"><!--
    InstanceBegin template="/Templates/temp.dwt.php"
    codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=utf-8" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>Untitled Document</title>
    <!-- InstanceEndEditable -->
    <link href="global.css" rel="stylesheet" type="text/css"
    />
    <!-- InstanceBeginEditable name="head" -->
    <script src="SpryAssets/xpath.js"
    type="text/javascript"></script>
    <script src="SpryAssets/SpryData.js"
    type="text/javascript"></script>
    <script type="text/javascript">
    <!--
    var ds1 = new
    Spry.Data.XMLDataSet("xml/detail.php><?php echo(
    isset($_GET['projectID'])?$_GET['projectID']:'' ); ?>", "row");
    //-->
    </script>
    <!-- InstanceEndEditable -->
    </head>
    <body class="oneColFixCtr">
    <div id="container"><!-- InstanceBeginEditable
    name="Main Content" -->
    <div id="mainContent">
    <h1> </h1>
    <p> </p>
    <!-- end #mainContent -->
    </div>
    <!-- InstanceEndEditable -->
    <div id="footer">
    <img src="images/banner.gif" width="500" height="66"
    alt="Plymouth Road Architects" />
    <br />
    <div id="nav">
    <table width="500" border="0" cellspacing="2"
    cellpadding="2">
    <tr>
    <td><div align="center"><a href="
    http://plymouthroadarchitects.com">HOME</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="company_info.php">ABOUT/CONTACT
    US</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="new_homes.php">NEW HOMES</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="additions.php">ADDITIONS</a></div></td>
    <td><div align="center"><img
    src="images/bullet.gif" alt="" width="8" height="8"
    /></div></td>
    <td><div align="center"><a
    href="main_street.php">MAIN
    STREET</a></div></td>
    </tr>
    </table>
    </div>
    </div>
    <!-- end #container --></div>
    </body>
    <!-- InstanceEnd --></html>
    Sorry for all the confusion and not submitting this code to
    you earlier on this forum. I really do appreciate your feedback and
    assistance

  • Getting blobs from databases

    Hi!
    Im trying to get a blob from a database and write it to a file, but I just can't get the Blob value, I just recieve the adress. I've tried InputStream and getBytes but none of them does what I want. getBytes where closest but because it requires two inparameters (long pos, int length) and blob.length gives an long i can't figure out how many bytes to get. Anyone got any sugestions?

    Agrawal.
    I've read through both those pages (even thou i've already managed to make the connection to mysql) and I still can't work around my problem. the method getBytes(), requires two parameters, one that tells it where to start reading and one telling it how long it should read. If I leave one out it will inevitable lead to problems. So I still need to figure out a way to get the length of the blob in a int to make this work. but since the blob.length() method returns a long wich I can't convert I'm stuck!

  • How to show in a report a pdf blob from database

    Hi all
    We are working on report 6i and report 10. We have a report wich needs to show a blob field from database that storages a pdf (type application/pdf). OLE2 is deprecated. The pdf blob field must be displayed in a preview and must be printed. In local, it works. When it works on a browser, the pdf blob field is missing. If we load the field into a pdf file, the field is not visible in the browser.
    Do not get it to work. How I can implement? Could you give us any example for this?

    In local, it works. What do you mean by that exactly? You see the pdf in Reports Builder?
    If you just want to show the pdf in a browser (not embedded in a report) it is easy to use mod_plsql. You can have a simple db procedure like this to show any kind of blob:
    procedure show_webdoc(io_blob    in out nocopy blob
                         ,i_mimetype in varchar2
                         ,i_filename in varchar2)
    is
    begin
       if dbms_lob.getlength(io_blob) >0 then
          owa_util.mime_header(nvl(i_mimetype,'application/octet'),false);
          htp.p('Content-length: ' || dbms_lob.getlength(io_blob));
          htp.p('Content-Disposition:  inline; filename="'||i_filename|| '"');
          owa_util.http_header_close;
          wpg_docload.download_file(io_blob);
       end if;
    end show_webdoc;

  • Dowload blobs from Database

    I know this is not the best way to store files but I have inherited an old php script which I am converting to CF because php is useless.
    Now i have a script to do this in php but can this be achived with CF? It is just a quick fix until I have time to rework the CMS
    <?php
    if(isset($_GET['id']))
    // if id is set then get the file with the id from database
    $id    = $_GET['id'];
    $query = "SELECT name, type, size, content " .
             "FROM upload WHERE id = '$id'";
    $result = mysql_query($query) or die('Error, query failed');
    list($name, $type, $size, $content) =                                  mysql_fetch_array($result);
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=$name");
    echo $content;
    i
    exit;
    ?>

    My php experience is NILL, but applying basic coding experience I believe your CFML will be close to this.
    <cfif structKeyExists(url,"id")>
      <cfquery datasource="..." name="result">
        SELECT name,type,size,content
        FROM upload
        WHERE id = <cfqueryparam value="#url.id#" cfsqltype="cf_sql_integer">
      </cfquery>
      <cfheader name="Content-Disposition: atachment; filename=#result.name#">
      <cfcontent type="#result.type#" reset="yes">
      #result.content#
    </cfif>
    If any of this content can be binary, then you may also need to use one or more of the toBinary() toBase64(), isBinary(), binaryDecode() or other relevant functions.

  • Convert pdf from database system to pdf creator with our LOGO possible?

    We work in our company with a data base programme and when we creat a pdf with the info of these programme we want our LOGO automaticly intergrate in these new PDF.

    1. What software currently creates the PDF from database info?
    2. Is this software on each user's computer, on the database server, a web server, or somewhere else?

  • Retrieval of image (Blob) from database - doesn't always work in JSP - Why?

    In my JSP pages, when an image needs to be retrieved, I direct <img src> to a servlet that handles image processing.
    As an example, if I have 30 products that need to be shown on 1 webpage, there will be 30, dynamically generated, <img src="go.imageServlet?id=a1"> tags/statements. The servlet, when called, will make a connection to the database, run a query for the image requested (fetched as type Blob), image displays in <img src> area of JSP page, and finally the ResultSet, Statement, and Connection object(s) are closed.
    I tested this out, and unfortunately, to my surprise, and disappointment, a few images did not display on the page. Though the images are in the database table. I'm a little lost as to why this problem is occurring.
    Can someone please shed some light on this for me?

    evnafets wrote:
    If you request just one image, does that image come back broken, or is it different images that are 'broken' each time?On a page of almost 30 image requests (thumbnail size), it varies, but typically, 1-3 images are 'broken' each time. And they are not always the same images. Very strange.
    There may potentially be thread concurrency errors depending upon how you have written your servlet - ie one request for an image interfering with another because they use the same variable.
    To make it threadsafe, in your servlet make sure that you only use variables local to the doGet/doPost method, and not any class attributes.In my JSP page that makes the requests for these images, a String array generates the <img src> tags on the page, as a very basic example :
    <%  for(int i=0; i<products.length; i++) {
    %>
          <img src="go.imageP?imageNumber=<%=products[[0]%>">
    <% }//for %>
    Sorry for not posting code snippets from my servlet in my first post of this topic....
    Here is my servlet snippet -     public class ImageProcessingServlet extends HttpServlet {
              public Connection conn = null;
              public ResultSet rs = null;
              public Statement stmt = null;
              public PreparedStatement pstmt = null;          
              public PrintWriter out = null;     
              public String siteNameReference = "";
              int maxFullSizeImageWidth = 600;          
              int maxSizeImageWidth = 300;
              int maxSizeThumbWidth = 140;
              int maxImageFields = 4;
              String errorMessage = "";               
              public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
                   doPost(req,res);
              public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
              try {                       
         HttpSession session = req.getSession();
         siteNameReference = req.getParameter("snr");
         String process = req.getParameter("process");
         if(process == null) process = "";
                   Context ctx = new InitialContext();
              if(ctx == null )
    throw new Exception("Boom - No Context");
              DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/imageDB");
         conn = ds.getConnection();
         stmt = conn.createStatement();      
              rs = stmt.executeQuery("Select "+imageNumber+" from images");
              rs.next();
              Blob blobImage = rs.getBlob(1);               
              getImage(blobImage,"thumb",res);
              if(rs != null) { rs.close(); }
              rs = null;
         if(stmt != null) { stmt.close(); }
         stmt = null;
         if(pstmt != null) { pstmt.close(); }
         pstmt = null;
         conn.close();
         conn = null;          
              }//try
         catch (Exception e) { }
         finally {
                   if (rs != null) {
                   try { rs.close(); } catch (SQLException e) { ; }
                   rs = null;
                   if (stmt != null) {
                   try { stmt.close(); } catch (SQLException e) { ; }
                   stmt = null;
                   if (pstmt != null) {
                   try { pstmt.close(); } catch (SQLException e) { ; }
                   pstmt = null;
                   if (conn != null) {
                   try { conn.close(); } catch (SQLException e) { ; }
                   conn = null;
              }//finally
         }//post          
              public void getImage(Blob blobImage, String imageType, HttpServletResponse res) {
                   try {                                              
                        //imageType will = Super = 600
                        // = Large = 300
                        //               = Thumb = 150
                        res.reset();
                        res.setContentType("image/jpeg");
                        BufferedInputStream bis = new BufferedInputStream(blobImage.getBinaryStream());                    
                        BufferedOutputStream bos = new BufferedOutputStream(res.getOutputStream());                                                            
                        if(imageType.equals("super")) {
                        byte[] imageBytes = new byte[(int)blobImage.length()]; //picture size           
         int length;
         while((length = bis.read(imageBytes)) > 0) {
    bos.write(imageBytes, 0, length);
         bos.flush();     
                   res.flushBuffer();
                        } else
                        if(imageType.equals("large")) {
                             resize(bis,bos,maxSizeImageWidth);
                             bos.flush();
                             res.flushBuffer();
                        } else
                        if(imageType.equals("thumb")) {
                             resize(bis,bos,maxSizeThumbWidth);
                             bos.flush();
                             res.flushBuffer();                         
                        }//if
                        //close streams
                        bis.close();
                        bos.close();
                   }//try
                   catch(Exception e) {}
              }//end          
         public void resize(BufferedInputStream bis, BufferedOutputStream bos, int maxImageWidth) {
              try {                            
              BufferedImage bufimg = ImageIO.read(bis);                                         
              //size of image
              int img_width = bufimg.getWidth();
              int img_height = bufimg.getHeight();               
              double scale = (double)maxImageWidth/(double)img_width;                    
              Image sized = getScaledInstanceAWT(bufimg, scale, Image.SCALE_SMOOTH);
              //convert image to BufferedImage
              BufferedImage resized = toBufferedImage(sized, BufferedImage.TYPE_INT_RGB);                                                                                
                        ImageIO.write(resized,"jpeg",bos);                                                                           
         }//try
         catch(Exception e){}
    }//end
    Edited by: webnotick on Apr 13, 2010 12:24 PM
    --added a method to the code snippet --                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Displaying BLOB from Database

    Hi All,
    I am trying to preview a 'jpeg' image which is stored in my database. The images get inserted into the DB without any trouble, but on retrieving the images I get 'broken links' to the images. Please Help:
    PROCEDURE GET_TEAM_LOGO(team_name VARCHAR2)
    AS
    vblob BLOB;
    buf RAW(32000);
    buf_size INTEGER := 32000;
    offset INTEGER := 1;
    len NUMBER;
    mime_type VARCHAR2(30);
    BEGIN
    auth_proc;
    -- get image_data and its mime type from the database
    WHERE LOGO_ID=position;
    htp.p('This is the value of team:'|| team_name ||'<br>');
    SELECT logo_image, logo_type INTO vblob, mime_type
    FROM LOGO_TABLE
    WHERE group_name = team_name;
    -- set the mime type for the http protocol
    owa_util.mime_header('image/jpeg');
    -- read the data with htp package
    len:=dbms_lob.getlength(vblob);
    WHILE offset < len LOOP
    dbms_lob.read(vblob,buf_size,offset,buf);
    htp.prn(utl_raw.cast_to_varchar2(buf));
    offset:=offset+buf_size;
    END LOOP;
    -- check for exception
    EXCEPTION
    WHEN OTHERS THEN
    htp.p(SQLCODE || SQLERRM);
    END;
    Thanks,
    Peter

    Hi!
    I've used this code successfylly in a mod_plsql procedure.
    Can be used as following:
    htp.img('http://yourhost:port/<dad>/image.get_image?p_picture_id=123,'"right"',null,null,'width=107 height=66 border=1');
    procedure get_image
    ( p_picture_id number
    ) as
    cursor c_pict
    ( b_picture_id number
    ) is
    select pict.picture -- blob column
    , pict.format -- Gif/Jpeg etc.
    from pictures pict
    where pict.picture_id = b_picture_id
    r_pict c_pict%rowtype;
    v_blob BLOB;
    v_amt NUMBER := 30;
    v_off NUMBER := 1;
    v_raw RAW(4096);
    begin
    open c_pict(p_picture_id);
    fetch c_pict into r_pict;
    if c_pict%notfound
    then
    close c_pict;
    else
    close c_pict;
    owa_util.mime_header('image/'||r_pict.format);
    begin
    loop
    dbms_lob.read(r_pict.picture,v_amt,v_off,v_raw);
    htp.prn(utl_raw.cast_to_varchar2(v_raw));
    v_off := v_off+v_amt;
    v_amt := 4096;
    end loop;
    exception
    when no_data_found
    then
    null;
    end;
    end if;
    end get_image;

  • Select data from database via XML

    I want to select data for display and insert data to tables via XML, and I want
    to do this from a browser.
    I am using "Oracle8i Enterprise Edition Release 8.1.7.4.0" on HP-UX server
    with "JServer Release 8.1.7.4.0.".
    The oracle documentation says I need the following in order to do this.
    1. XML-SQL Utility
    2. XML Parser for Java, V2
    3. JDBC driver
    4. JDK
    5. A Java compliant web server
    6. XSL Servlet
    How do I verify, if the above software list is available in my environment.
    What are all available within the database and what are other software I need to
    install.
    Thanks
    Pushparaj

    It's a classpath problem. Either you mistyped the class name, or you don't have the class in your classpath. I think Oracle's drivers come in db12.zip or db12.jar or some such. Whatever that jar or zip file is, it has to be in your classpath, but it's not.
    Or it is in your classpath, but you're in an appserver context where the classloader that the container provides for your app uses something other than the classpath variable. For instance, in tomcat, the jar file would be uder webapps/yourApplication/WEB-INF/lib I think.

  • Extract data from database to xml ?

    is there any API, classes or tools ready to extract data from oracle database and generate xml files, Instead to implement a DOM class and build little by little the xml file??
    thanks for every info in advance.

    Yes, download the Oracle XML Development Kit from Oracle's website and look at the documentation of the XML-SQL Utility.

  • Need to Move contents of BLOB from database to middle-tier file system

    I need to be able to move the contents of a BLOB (which is a PDF file) from the database to a specified location in the middle-tier file system (running 9iAS). There does not seem to be the equivalent package or other built-in functionality to DBMS_LOB (for moving INTO the database, which is amazing. Does anyone have a java bean or (?) which can accomplish this simingly simple task??

    The java bean should work to extract from the database to a binary file on either Unix or Windows. As long as the file is in .bmp format in the database, you can save the file as .bmp on you file system and everything should be alright.
    Or, perhaps, am I not understanding your question?
    Good Luck
    Eric Kamradt

  • Calling form .fmx or report .rep from database trigger. (URGENT PL.)

    can we call an form (.fmx) or a report (.rep) from a database trigger. that is when there is some insertion in the table i want to call a report which will take the parameters from the table changed.
    regards
    vishal

    JDeveloper and ADF

Maybe you are looking for