put an Hashtable into a blob ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: put an Hashtable into a blob ?

  1. #1
    lydia Guest

    put an Hashtable into a blob ?


    hello,
    it is possible to put an Hashtable into a java.sql.blob ?
    what can I do ?
    Lydia

  2. #2
    Carey Nation Guest

    Re: put an Hashtable into a blob ?


    Maybe serialize the hashtable through ObjectOutputStream and through
    one of the byte output streams. Maybe then you can get a buffer with the
    data in it. Stuff that into your blob...

    "lydia" <mulerol@*******.com> wrote:
    >
    >hello,
    >it is possible to put an Hashtable into a java.sql.blob ?
    >what can I do ?
    > Lydia



  3. #3
    lydia Guest

    Re: put an Hashtable into a blob ?


    thank you for your response

    but a have some util problem :

    this my code :
    java.sql.Connection con =

    DriverManager.getConnection("...");
    String stmt = "SELECT BLOB FROM USRS WHERE ID=?
    FOR UPDATE";
    PreparedStatement prep = con.prepareStatement(stmt);

    java.sql.ResultSet jrs = prep.executeQuery();
    jrs.next();
    oracle.sql.BLOB b =(oracle.sql.BLOB)((oracle.jdbc.driver.OracleResultSet)jrs).getBLOB(1);

    con.setAutoCommit(false);


    Then how to put the hashtable in the blob?

    - ouptustream ouput = blob.getbinaryoutpstream()
    -obj = objectoutputstream(output)
    - obj.writeObject(hashtable) (with my code this
    instruction causes an sql error (fech out of statement ???)

    jrs.close();
    con.commit;
    con.close();


    Any idea ?


    thank for your help



    "Carey Nation" <cnation@pathfire.com> wrote:
    >
    >Maybe serialize the hashtable through ObjectOutputStream and through
    >one of the byte output streams. Maybe then you can get a buffer with the
    >data in it. Stuff that into your blob...
    >




  4. #4
    Carey Nation Guest

    Re: put an Hashtable into a blob ?


    It looks like you've confused the serialization directions. No worries,
    it's wierd.

    Use ObjectOutputStream to get something that you can put into the
    database, i.e. your blob data. Use ObjectInputStream to get it back into
    a hashtable after you've done your 'select blob...' thing.

    Hope this helps...

    "lydia" <mulerol@*******.com> wrote:
    >
    >thank you for your response
    >
    >but a have some util problem :
    >
    >this my code :
    >java.sql.Connection con =
    >
    >DriverManager.getConnection("...");
    > String stmt = "SELECT BLOB FROM USRS WHERE ID=?
    >FOR UPDATE";
    > PreparedStatement prep = con.prepareStatement(stmt);
    >
    > java.sql.ResultSet jrs = prep.executeQuery();
    > jrs.next();
    > oracle.sql.BLOB b =(oracle.sql.BLOB)((oracle.jdbc.driver.OracleResultSet)jrs).getBLOB(1);
    >
    > con.setAutoCommit(false);
    >
    >
    >Then how to put the hashtable in the blob?
    >
    > - ouptustream ouput = blob.getbinaryoutpstream()
    > -obj = objectoutputstream(output)
    > - obj.writeObject(hashtable) (with my code this
    > instruction causes an sql error (fech out of statement ???)
    >
    > jrs.close();
    > con.commit;
    > con.close();
    >
    >
    >Any idea ?
    >
    >
    > thank for your help
    >
    >
    >
    >"Carey Nation" <cnation@pathfire.com> wrote:
    >>
    >>Maybe serialize the hashtable through ObjectOutputStream and through
    >>one of the byte output streams. Maybe then you can get a buffer with the
    >>data in it. Stuff that into your blob...
    >>

    >
    >



  5. #5
    lydia Guest

    Re: put an Hashtable into a blob ?


    I think I write my hashtable into the blob
    Now I want to read the hashtable from the blob :

    I have another pb : java.sql.SQLException: ORA-06550: line 1, column
    22:
    PLS-00302: component 'GETCHUNKSIZE' must be declared
    ORA-06550: line 1, column 7:

    are you any idea ? what's this component ? I don't find anything in doc oracle
    about this pb !

    this is the code :
    stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery("SELECT BLOBOBJECT
    FROM UTILISATEUR WHERE ID = 'truc'");
    while (rs.next()) {
    data = ((OracleResultSet)rs).getBLOB(1);
    int taille = data.getChunkSize();
    InputStream input = data.getBinaryStream();
    byte [] tableau = new byte[taille];
    input.read(tableau);
    ByteArrayInputStream bos = new
    ByteArrayInputStream(tableau);
    ObjectInputStream p = new ObjectInputStream(bos);
    hessai = (Hashtable) p.readObject();
    String bonjour = (String) hessai.get("one");
    String coucou= (String) hessai.get("two");
    input.close();
    p.close();
    con.commit();
    }
    rs.close();



    "Carey Nation" <careynation@ga.prestige.net> wrote:
    >
    >It looks like you've confused the serialization directions. No worries,
    >it's wierd.
    >
    >Use ObjectOutputStream to get something that you can put into the
    >database, i.e. your blob data. Use ObjectInputStream to get it back into
    >a hashtable after you've done your 'select blob...' thing.
    >
    >Hope this helps...
    >
    >"lydia" <mulerol@*******.com> wrote:
    >>
    >>thank you for your response
    >>
    >>but a have some util problem :
    >>
    >>this my code :
    >>java.sql.Connection con =
    >>
    >>DriverManager.getConnection("...");
    >> String stmt = "SELECT BLOB FROM USRS WHERE ID=?
    >>FOR UPDATE";
    >> PreparedStatement prep = con.prepareStatement(stmt);
    >>
    >> java.sql.ResultSet jrs = prep.executeQuery();
    >> jrs.next();
    >> oracle.sql.BLOB b =(oracle.sql.BLOB)((oracle.jdbc.driver.OracleResultSet)jrs).getBLOB(1);
    >>
    >> con.setAutoCommit(false);
    >>
    >>
    >>Then how to put the hashtable in the blob?
    >>
    >> - ouptustream ouput = blob.getbinaryoutpstream()
    >> -obj = objectoutputstream(output)
    >> - obj.writeObject(hashtable) (with my code this
    >> instruction causes an sql error (fech out of statement ???)
    >>
    >> jrs.close();
    >> con.commit;
    >> con.close();
    >>
    >>
    >>Any idea ?
    >>
    >>
    >> thank for your help
    >>
    >>
    >>
    >>"Carey Nation" <cnation@pathfire.com> wrote:
    >>>
    >>>Maybe serialize the hashtable through ObjectOutputStream and through
    >>>one of the byte output streams. Maybe then you can get a buffer with

    the
    >>>data in it. Stuff that into your blob...
    >>>

    >>
    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center