JDBC and Long RAW datatypes

I have written a Java/JDBC program that grabs jpeg images. I would like to store them in an Oracle database in a LONG RAW column (for legacy databases b4 BLOBs). Can someone show me some sample code that would allow me to do this??? All help is GREATLY appreciated.
TIA
RHC

From http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements001.htm#i54330
>
RAW(size)
Raw binary data of length size bytes. Maximum size is 2000 bytes. You must specify size for a RAW value.
LONG RAW
Raw binary data of variable length up to 2 gigabytes.

Similar Messages

  • Migration of LONG and LONG RAW datatype

    Just upgraded a DB from 8.1.7.4 to 10.2.0.1.0. In the post-upgrade tasks, it speaks of migrating tables with LONG and LONG RAW datatypes to CLOB's or BLOB's. All of my tables in the DB with LONG or LONG RAW datatypes are in the sys, sysman, mdsys or system schemas (as per query of dba_tab_columns). Are these to be converted? Or, does Oracle want us to convert user data only (user_tab_columns)?

    USER_TAB_COLUMNS tells you the columns in the tables owned by the current user. There may well be many users on your system that you created that contain objects. I suppose you could log in to each of those schemas and query their USER_TAB_COLUMNS table, but it's probably easier to query DBA_TAB_COLUMNS with an appropriate WHERE clause on the owner of the objects.
    Justin

  • How can i read a stored picture in oracle Long Raw datatype? blob or clob?

    How can i read a stored picture in oracle Long Raw datatype? Like a blob or clob?....i am using jdk 1.3
    This is because...i tried to read it like a blob but i obtain a exception...about Type of column no valid......but the column exist....and it contains the long raw datatype of the pictures.....this is my code:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.BLOB;
    import oracle.sql.BLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.*;
    class rec_ima1
    public static void main(String h[])
    Connection con = null;
    Blob bl;
    final ImageIcon image1;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    if (!rs.next())
    System.out.println("Empty Result Set");
    bl = rs.getBlob(5);
    if (bl == null) {
    System.out.println("Null Blob");
    return;
    InputStream is = bl.getBinaryStream();
    int imageLength = (int) bl.length();
    System.out.println(imageLength);
    System.out.println(bl.length());
    byte[] imageData = new byte [imageLength];
    is.read(imageData, 0, imageLength);
    image1 = new ImageIcon(imageData);
    photo = new JPanel() {
    public void paint(Graphics g){
    g.setColor(Color.lightGray);
    g.drawImage(image1.getImage(), 0, 0, this);
    } catch (Exception e) {
    e.printStackTrace();
    Now i tried using clob:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.CLOB;
    import oracle.sql.CLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.CallableStatement;
    class rec_ima4
    public static void main(String h[])
    Connection con = null;
    Clob cl;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    con.setAutoCommit (false);
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    while (rs.next()) {
    oracle.sql.CLOB clob = (CLOB) rs.getObject(5); //line 47
    } catch (Exception e) {
    e.printStackTrace();
    This is the runtime exception:
    java.lang.ClassCastException: [B
    at rec_ima4.main(rec_ima4.java:47)

    Thanks by answering to me......
    Well....i did that....but what is ImageIO?....
    I declared a ImageIcon imageIO, but this give me the following:
    rec_ima3.java:49: cannot resolve symbol
    symbol : class BufferedImage
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    rec_ima3.java:49: cannot resolve symbol
    symbol : variable ImageIO
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    What classes i have to import?.....what is ImageIO?
    Thanks

  • How to view contents in Long Raw datatype column

    Hi,
    We have two node RAC database with 10.2.0.4.0 version.
    OS - IBM AIX.
    We have a table with a column with datatype "LONG RAW" in production. It stores image files.
    We need to send the images from few rows to third party vendor. Basically, they need to view the images.
    Earlier, I have exported to dump file using datapump and sent to vendor. but vendor is telling that they are not able to view the images. Can you please suggest best method to transfer the images (LONG RAW datatype) and the method to view them.

    We have a table with a column with datatype "LONG RAW" in production. It stores image files.
    We need to send the images from few rows to third party vendor. Basically, they need to view the images.
    Earlier, I have exported to dump file using datapump and sent to vendor. but vendor is telling that they are not able to view the images. Can you please suggest best method to transfer the images (LONG RAW datatype) and the method to view them.How is the vendor trying to use the extracted images? Data exported with datapump must be imported into another database with datapump. The same applies to the exp utility (must use imp to load into a database).
    If you're careful you should be able to write a binary file using utl_file.
    Regarding the long raw, is there any way you could convert to BLOBS? Longs and Long raws are notoriously hard to work with

  • How to find the long/raw datatype tables

    HI ppl,
    I want to find out the long/raw datatype tables in Oracle database.
    Please provide the query..
    Plz help.
    Oracle version :10gr2
    platform:HP-UNIX

    Hi,
    is this is what you are looking for?
    SELECT
         TABLE_NAME,
          COLUMN_NAME,
          OWNER
    FROM
          DBA_TAB_COLUMNS
    WHERE
          DATA_TYPE IN('LONG','RAW')Regards

  • Caching RAW and LONG RAW objects

    Hi,
    Is there any way to cache RAW and LONG RAW object like BLOB caching?
    Thanks

    Is there any way to cache RAW and LONG RAW object like BLOB caching?What is the version?
    to fetch long fetch size character of bytes you must use any one of below three.
    1)Primary key
    2)ROWID
    3)Unique columns

  • Jdbc session - LONG RAW or BLOB ?

    Hello,
              My over-large session data cannot use the LONG RAW data type, for session data field. I think that is a jdbc driver limitation.
              Session data does not appear to be saved at all if I use a 'BLOB' instead of LONG RAW. Does anyone know if this usually works ?
              The drivers I have tried are -
              oracle.jdbc.driver.OracleDriver
              weblogic.jdbc.oci.Driver
              Oracle 817
              Weblogic 6.1 sp 3
              thanks in advance,
              John
              

    Kiran,
    A long raw column can store up to 2 Go and you can have only one by table.
    With 9i, BLOB column can store up to 4Go and you can have as so many you want.
    With 10g, BLOB column can store up to 8To
    I suggest you to use BLOB columns.
    Francois

  • Oraclebinary  and log raw datatypes

    hi
    i have a table (oracle XE 10g) with a column LONG RAW data types, the column contains a XML file for XSLT tranformation.
    i want read th column and i write this code but it don't works!!!
    Private Sub leggiRiparto()
    Dim codiceProvincia As String
    Dim codiceComune As String
    Dim codtipoelezione As String
    'query per la lettura dalla tabella outputscrutini del Db elez
    Dim strSQL As New String("SELECT o.DATAELEZIONE, o.CODPROVINCIA,o.CODCOMUNE,o.CODTIPOELEZIONE, o.XML, c.DESCCOMUNE " & _
    "FROM outputscrutinio o, comune c " & _
    "WHERE o.dataElezione = " & dataElezione & " and o.codtipoelezione = " & tipoelezione & _
    " AND o.CODPROVINCIA = c.CODPROVINCIA " & _
    " AND o.CODCOMUNE = c.CODCOMUNE " & _
    "ORDER by o.codprovincia, o.codcomune")
    Dim riparti As OracleCommand ' New OracleCommand(strSQL, dbElezioniDDE)
    riparti = New OracleCommand(strSQL, dbElezioniDDE)
    Try
    'ApriDB()
    Dim dtRead As OracleDataReader = riparti.ExecuteReader
    If Not dtRead.HasRows Then
    MessageBox.Show("Attenzione non ci sono riparti disponibili ! Contattare l'amm.re del DB")
    Else
    While (dtRead.Read())
    codiceProvincia = dtRead.Item("CODPROVINCIA")
    codiceComune = dtRead.Item("CODCOMUNE")
    codtipoelezione = dtRead.Item("CODTIPOELEZIONE")
    Dim blob As OracleBinary = dtRead.GetOracleBinary(4)
    'Dim blob As OracleBlob = dtRead.GetOracleBlob(4)
    Dim indice As Integer = blob.Length
    Dim nomefile As String = "Riparto Seggi" & "-" & dataElezione & "-" & codtipoelezione & "-" & codiceProvincia & "-" & codiceComune
    Dim fileXML(indice) As Byte
    End While
    End If
    Catch ex As OracleException 'catch per eccezioni Oracle
    Select Case ex.Number
    Case 12545
    MessageBox.Show("Il database è al momento non disponibile.")
    Case Else
    MessageBox.Show("errore database: " & ex.Message.ToString)
    End Select
    Catch ex As Exception
    MessageBox.Show("Errore Apertura DB DDE : " & ex.Message & vbCrLf & "StackTrace : " & ex.StackTrace, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End
    Finally
    riparti.Dispose()
    'dbElezioniDDE.Close()
    'dbElezioniDDE.Dispose()
    End Try
    End Sub

    I'm sorry but the post was incomplete!
    Then the problem is when I read the XML data
    As OracleBinary dtRead.GetOracleBinary
    Dim blob As OracleBinary = dtRead.GetOracleBinary(4)
    Dim indice As Integer = blob.Length
    that by obtaining blob.Length = 0
    while the other fields in the select statement is accurate
    Thanks

  • Error when querying long raw

    Hi,
    I am using developer 6i with oracle 10.2.0.4 on win 2008.
    I created a table as below:
    create table image_table (filename varchar2(255) primary key, image long raw);
    i created a trigger in forms to upload a image and store the link in the database. The image is stored in a directory.
    The image link is saved in image_table.
    But when i query the table, i get the below error
    SQL> select * from image_table;
    ERROR:
    ORA-00932: inconsistent datatypes
    no rows selected
    When i query the table in TOAD, i get the output as
    FILENAME, IMAGE
    ateeq, (BLOB)
    Please suggest how to solve this problem.
    Thanks,

    the LONG and LONG RAW datatype have been deprecated in Oracle 8.0, in 1998, so 14 years ago!
    Is there any sound reason why you can't use a BLOB?
    a LONG ROW column can not be displayed directly, so a
    select * from image_table
    where one of the columns is a LONG RAW is expected not to work,
    and if you would have read documentation (which you never do, I remember you from previous doc questions), you would have known and not have asked Yet Another Redundant Question!
    Sybrand Bakker
    Senior Oracle DBA

  • HOW TO RETRIEVE A LONG RAW COLUMN FROM A TABLE AND WRITE TO OS FILE

    Good evening.
    Please how can I read a long raw datatype from a table and insert into an operating system file using PL/SQL.
    Thank you.

    What does this have to do with LONG RAW? It is about UTL_FILE and not especially great code.
    The question is how to retrieve and write LONG RAW and that is quite a different matter.
    First you must convert it to BLOB.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
    Then you can write it out to the file system
    http://www.morganslibrary.org/reference/utl_file.html
    Look at the "Extract Blob" demo

  • LONG RAW Columns and  Replication Set-up

    we are working to set-up a replicated environment for all of
    our Oracle Applications.
    I could not get a clear understanding which Version Oracle will
    support BLOB/CLOB/LONG RAW replication support or
    Whether we can plan for Replicating such kind of Applications.
    I read from one of Oracle Press book - "Oracle Backup &
    Recovery" it is documented
    that Oracle doesn't replication support for columns that use
    BLOBs,CLOBs ( Page
    no. 434 )
    As one of our application was designed using LONG RAW Column, I
    was wondering
    about carrying the existing LONG RAW column to be replicated
    like a CLOB/BLOB, if oracle supports Replication of BLOB/CLOB.
    It will be of great help, if you can provide some insight in the
    complexity of
    having BLOBs in the applications to go further on making our
    efforts to have a
    Replicated environment set-up.
    Thanking you in anticipation.
    Bhanu Prakash
    < [email protected]>

    1) LONG and LONG RAW have been depricated since 8i so you shouldn't be using them ever for anything.
    2) LONG and LONG RAW don't even have decent support to be manipulated from PL/SQL so there is essentially no SQL support.
    3) It would be very rare that you would have anything to index in a LONG or a LONG RAW from a functionality standpoint. You're not likely, for example, to want to store more than 4k of data in a LONG and then do things like search for strings that start with a particular phrase. You're very very unlikely to want to search a binary LONG RAW to look for rows where the binary data starts with a particular string of bytes. You'd potentially want to be able to use Oracle Text on a LONG field to search for particular words and phrases in the text but I'm not sure that existed prior to LONGs being depricated.
    Justin

  • Can't fetch clob and long in one select/query

    I created a nightmare table containing numerous binary data types to test an application I was working on, and believe I have found an undocumented bug in Oracle's JDBC drivers that is preventing me from loading a CLOB and a LONG in a single SQL select statement. I can load the CLOB successfully, but attempting to call ResultSet.get...() for the LONG column always results in
    java.sql.SQLException: Stream has already been closed
    even when processing the columns in the order of the SELECT statement.
    I have demonstrated this behaviour with version 9.2.0.3 of Oracle's JDBC drivers, running against Oracle 9.2.0.2.0.
    The following Java example contains SQL code to create and populate a table containing a collection of nasty binary columns, and then Java code that demonstrates the problem.
    I would really appreciate any workarounds that allow me to pull this data out of a single query.
    import java.sql.*;
    This class was developed to verify that you can't have a CLOB and a LONG column in the
    same SQL select statement, and extract both values. Calling get...() for the LONG column
    always causes 'java.sql.SQLException: Stream has already been closed'.
    CREATE TABLE BINARY_COLS_TEST
    PK INTEGER PRIMARY KEY NOT NULL,
    CLOB_COL CLOB,
    BLOB_COL BLOB,
    RAW_COL RAW(100),
    LONG_COL LONG
    INSERT INTO BINARY_COLS_TEST (
    PK,
    CLOB_COL,
    BLOB_COL,
    RAW_COL,
    LONG_COL
    ) VALUES (
    1,
    '-- clob value --',
    HEXTORAW('01020304050607'),
    HEXTORAW('01020304050607'),
    '-- long value --'
    public class JdbcLongTest
    public static void main(String argv[])
    throws Exception
    Driver driver = (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    DriverManager.registerDriver(driver);
    Connection connection = DriverManager.getConnection(argv[0], argv[1], argv[2]);
    Statement stmt = connection.createStatement();
    ResultSet results = null;
    try
    String query = "SELECT pk, clob_col, blob_col, raw_col, long_col FROM binary_cols_test";
    results = stmt.executeQuery(query);
    while (results.next())
    int pk = results.getInt(1);
    System.out.println("Loaded int");
    Clob clob = results.getClob(2);
    // It doesn't work if you just close the ascii stream.
    // clob.getAsciiStream().close();
    String clobString = clob.getSubString(1, (int)clob.length());
    System.out.println("Loaded CLOB");
    // Streaming not strictly necessary for short values.
    // Blob blob = results.getBlob(3);
    byte blobData[] = results.getBytes(3);
    System.out.println("Loaded BLOB");
    byte rawData[] = results.getBytes(4);
    System.out.println("Loaded RAW");
    byte longData[] = results.getBytes(5);
    System.out.println("Loaded LONG");
    catch (SQLException e)
    e.printStackTrace();
    results.close();
    stmt.close();
    connection.close();
    } // public class JdbcLongTest

    The problem is that LONGs are not buffered but are read from the wire in the order defined. The problem is the same as
    rs = stmt.executeQuery("select myLong, myNumber from tab");
    while (rs.next()) {
    int n = rs.getInt(2);
    String s = rs.getString(1);
    The above will fail for the same reason. When the statement is executed the LONG is not read immediately. It is buffered in the server waiting to be read. When getInt is called the driver reads the bytes of the LONG and throws them away so that it can get to the NUMBER and read it. Then when getString is called the LONG value is gone so you get an exception.
    Similar problem here. When the query is executed the CLOB and BLOB locators are read from the wire, but the LONG is buffered in the server waiting to be read. When Clob.getString is called, it has to talk to the server to get the value of the CLOB, so it reads the LONG bytes from the wire and throws them away. That clears the connection so that it can ask the server for the CLOB bytes. When the code reads the LONG value, those bytes are gone so you get an exception.
    This is a long standing restriction on using LONG and LONG RAW values and is a result of the network protocol. It is one of the reasons that Oracle deprecates LONGs and recommends using BLOBs and CLOBs instead.
    Douglas

  • Can we use BLOB instead of LONG RAW in JMSStore

    (Oracle 9i, Weblogic 8.1.2)
              We are putting in place a Dataguard environment (or standby database). In such environment, prod data is copied to another database in 'pseudo' real time. Unfortunately some 'old' datatypes are not supported by Dataguard. In JMS tables %JMSSTORE, the field RECORD is defined as LONG RAW and LONG RAW is one of the unsupported datatypes.
              Can we alter those tables in order to use BLOB instead of LONG RAW ?
              Regards,
              Bao Nguyen
              

    Hi Bao,
              Answers in-line:
              Bao Nguyen wrote:
              > (Oracle 9i, Weblogic 8.1.2)
              >
              > We are putting in place a Dataguard environment (or standby database). In such environment, prod data is copied to another database in 'pseudo' real time. Unfortunately some 'old' datatypes are not supported by Dataguard. In JMS tables %JMSSTORE, the field RECORD is defined as LONG RAW and LONG RAW is one of the unsupported datatypes.
              >
              > Can we alter those tables in order to use BLOB instead of LONG RAW ?
              Not supported in 8.1. A supported Oracle BLOB capability will be
              available in the next release. I can think of two
              possible work-arounds:
              (1) The following might work, but is not currently supported by
              BEA: Manually create the table with a BLOB type and use
              an Oracle OCI or BEA type IV driver. Definitely do NOT use
              an Oracle thin driver, as data corruption may result.
              (2) I recall that another customer had a replication product
              they were able to get working with LONG RAW by modifying
              the table definition so that the table's handle index was a primary key.
              I do not remember the name of the product.
              (The latter modification is supported for certain releases
              now - but I think this usage must be confirmed with customer support.)
              Tom
              >
              > Regards,
              >
              > Bao Nguyen
              >
              

  • Mapping CLOB and Long in xml schema

    Hi,
    I am creating an xml schema to map some user defined database objects. For example, for a column which is defined as VARCHAR2 in the database, I have the following xsd type mapping.
    <xsd:element name="Currency" type="xsd:string" />
    If the oracle column is CLOB or Long(Oracle datatype), could you please tell me how I can map it in the xml schema? I do not want to use Oracle SQL type like:
    xdb:SQLType="CLOB" since I need a generic type mapping to CLOB. Would xsd:string still hold good for CLOB as well as Long(Oracle datatype) ?
    Please help.
    Thanks,
    Vadi.

    The problem is that LONGs are not buffered but are read from the wire in the order defined. The problem is the same as
    rs = stmt.executeQuery("select myLong, myNumber from tab");
    while (rs.next()) {
    int n = rs.getInt(2);
    String s = rs.getString(1);
    The above will fail for the same reason. When the statement is executed the LONG is not read immediately. It is buffered in the server waiting to be read. When getInt is called the driver reads the bytes of the LONG and throws them away so that it can get to the NUMBER and read it. Then when getString is called the LONG value is gone so you get an exception.
    Similar problem here. When the query is executed the CLOB and BLOB locators are read from the wire, but the LONG is buffered in the server waiting to be read. When Clob.getString is called, it has to talk to the server to get the value of the CLOB, so it reads the LONG bytes from the wire and throws them away. That clears the connection so that it can ask the server for the CLOB bytes. When the code reads the LONG value, those bytes are gone so you get an exception.
    This is a long standing restriction on using LONG and LONG RAW values and is a result of the network protocol. It is one of the reasons that Oracle deprecates LONGs and recommends using BLOBs and CLOBs instead.
    Douglas

  • Restrict the LONG RAW Column with less than 32760 bytes in the SELECT

    When i am trying to access a LONG RAW Dataype wchich has characters greter than 32760 bytes i am getting this error.
    Error -6502: ORA-06502: PL/SQL: numeric or value error
    I came to know that PL/SQL will only be able to access the first 32760 bytes of a LONG RAW. If we try to fetch a LONG RAW from the database into PL/SQL variable which exceeds the 32760 byte limit then we encountered the above error.
    Can anyone tell to avoid this error can we write a query to restrict the output to get only those records which has LONG RAW length less than 32760 bytes.
    Since we canot use utl_raw.length() in the Select Statement, is there any function to restrict the the records for less than 32760 Bytes only for LONG RAW datatype, so that i will not get any records for more than 32760 bytes and we will not get this error.
    REquest you to please help.

    Hi
    we do not have an option of migrating the LONG RAW to BLOB or any kind of ALTER to the table.
    We want to restrict the use of Records from the Table which has data for LONG RAW column less than 32760 bytes, so that we will not get the PL/SQL numberic Error
    any function for LONG RAW that can be used in SQL like for varchar2 we can use
    select length(NAME) < 100 from tb_emp+
    i.e it will get records only which has NAME less than 100 characters.

Maybe you are looking for