Author |
Message
|
kash3338 |
Posted: Wed May 30, 2012 5:23 am Post subject: Converting Blob back to Sting |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
Hi,
We have a scenario where in we convert the payload data as Blob and load into Oracle DB from Message Flow. Later we have a Java application which reads the data from the Oracle DB.
The problem is, when the Java application reads the Blob data from DB, how do I convert the data to readable format again? I tried using Clob.getCharacterStream() method, but that returns me the data as a WMB BLOB type. I need it as a readable format which i inserted from flow. Any suggestions please?
Please dont question on the design, this is a scenario and just want to know how this can be implemented. We are well aware of how this can be acheived using only WMB.
WMB v7. Oracle 10g. Java 1.6. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed May 30, 2012 5:27 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The difference across the board between a BLOB and a readable character stream is the character code.
It's not clear what you mean by
Quote: |
Clob.getCharacterStream() method, but that returns me the data as a WMB BLOB type |
.
There shouldn't be any difference between reading a CLOB using JDBC in one java application and reading a CLOB using JDBC in another java application - so there isn't anything broker specific here. |
|
Back to top |
|
 |
kash3338 |
Posted: Wed May 30, 2012 5:41 am Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
mqjeff wrote: |
so there isn't anything broker specific here. |
Actually its not only specific to WMB, it involves all 3 (WMB, Oracle and java). The payload is casted to BLOB in WMB and loaded in Oracle DB and later a Java app reads the payload from the Oracle DB. Now while reading this payload from DB, we are not getting it in a readable format (the actual payload), but just getting the Blob content.
Guess any Java expert (who uses more of Java in WMB) would have come across this situation before. |
|
Back to top |
|
 |
smdavies99 |
Posted: Wed May 30, 2012 5:51 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
And the column datatype in the oracle table is? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed May 30, 2012 6:14 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
kash3338 wrote: |
Actually its not only specific to WMB, it involves all 3 (WMB, Oracle and java). The payload is casted to BLOB in WMB and loaded in Oracle DB |
That part is broker specific. It's not the part you are asking about.
kash3338 wrote: |
and later a Java app reads the payload from the Oracle DB. |
This part has nothing to do with Broker, unless Broker has inserted the data incorrectly. But you haven't shown that yet.
kash3338 wrote: |
Now while reading this payload from DB, we are not getting it in a readable format (the actual payload), but just getting the Blob content. |
That doesn't mean anything. Be specific about what "the blob content" actually is.
For example, are you receiving "424344" instead of "abc"?
Is there a difference between the data as read by the application, and the data as viewed in the database using Oracle standard database management tools? i.e. sqlplus? |
|
Back to top |
|
 |
kash3338 |
Posted: Wed May 30, 2012 9:54 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
mqjeff wrote: |
For example, are you receiving "424344" instead of "abc"? |
Exactly Yes. I am receiveing the data as BLOB as mentioned above by you.
mqjeff wrote: |
Is there a difference between the data as read by the application, and the data as viewed in the database using Oracle standard database management tools? i.e. sqlplus? |
No there is no difference in that. What i see in SQLPlus is what I get when I run the Java App. But thats the BLOB content (424344 instead of abc).
smdavies99 wrote: |
And the column datatype in the oracle table is? |
Its CLOB in Oracle.
mqjeff wrote: |
This part has nothing to do with Broker, unless Broker has inserted the data incorrectly. But you haven't shown that yet. |
There is nothing wrong in the data inserted from Broker.
Just to explain again, For example, if I get the input message as "abc" in my message flow, I convert it to BLOB and store in Oracle DB (with column type as CLOB) and the data is stored as 424344.
Now when I read that data using the Clob.getCharacterStream() method into a Clob datatype in my Java app, I just get 424344. How do I gte back my "abc" in the Java app is my question.
Hope this detail helps. |
|
Back to top |
|
 |
marko.pitkanen |
Posted: Wed May 30, 2012 10:00 pm Post subject: |
|
|
 Chevalier
Joined: 23 Jul 2008 Posts: 440 Location: Jamsa, Finland
|
Hi kash3338,
I might put you in the wrong path but I suggest you to do some Google search with keywords "hex, string (or ascii) and java".
--
Marko |
|
Back to top |
|
 |
kash3338 |
Posted: Wed May 30, 2012 10:36 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
marko.pitkanen wrote: |
I might put you in the wrong path but I suggest you to do some Google search with keywords "hex, string (or ascii) and java". |
It was the correct path. A small hint but very useful. I missed it somehow. Thanks. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu May 31, 2012 1:19 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
So if you are seeing that kind of value in the Oracle table itself, it is because you have converted a string into a blob in Broker without telling it what the CCSID is.
Or when you did the insert, broker did an automatic conversion of the BLOB to a string without specifying a CCSID.
I would try converting the BLOB to a CHAR and specify the correct CCSID in Broker and insert the CHAR rather than a BLOB. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu May 31, 2012 5:56 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If you insert a CLOB into oracle your WMB type should be CHARACTER.
If you insert a BLOB into oracle your WMB type should be BLOB.
A BLOB can also be defined as a array of bytes.
Before it can become a character stream you need to know the CCSID it is in...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu May 31, 2012 10:55 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
fjb_saper wrote: |
If you insert a CLOB into oracle your WMB type should be CHARACTER.
If you insert a BLOB into oracle your WMB type should be BLOB.
A BLOB can also be defined as a array of bytes.
Before it can become a character stream you need to know the CCSID it is in...
|
Whist is why it often pays to have a column called CCSID in the table alongside the one use for storing the data (the CLOB column). Then there is no excuse for not being able to reconstruct the original data. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
|