-
put an Hashtable into a blob ?
hello,
it is possible to put an Hashtable into a java.sql.blob ?
what can I do ?
Lydia
-
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
-
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...
>
-
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...
>>
>
>
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks