Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / August 2007

Tip: Looking for answers? Try searching our database.

INSERT binary data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gregor Kovač - 24 Aug 2007 07:12 GMT
Hi!

I'm using JDBC to connect to DB2. I have a binary data (array of bytes) and
want to save them.
Is it possible to write an INSERT statement to do this:
INSERT INTO TABLE (ID, BYTES) VALUES(1, '0x33 0x34') -- for example

or do I have to use PreparedStatement and setBlob/setBytes method?

Best regards,
       Kovi

Signature

____________________________

|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Knut Stolze - 24 Aug 2007 11:05 GMT
> Hi!
>
[quoted text clipped - 4 lines]
>
> or do I have to use PreparedStatement and setBlob/setBytes method?

You can do this:

INSERT INTO table(id, bytes) VALUES (1, x'3334')

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

Gregor Kovač - 24 Aug 2007 12:05 GMT
>> Hi!
>>
[quoted text clipped - 8 lines]
>
> INSERT INTO table(id, bytes) VALUES (1, x'3334')

I get SQL0408 : A value is not compatible with the data type of its
assignment target.  Target name is "bytes".
for this one.
The column bytes is defined like BLOB(1M) .

Best regards,
       Kovi

Signature

____________________________

|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Gregor Kovač - 25 Aug 2007 20:51 GMT
>>> Hi!
>>>
[quoted text clipped - 16 lines]
> Best regards,
>         Kovi

Tis works if the column is defined like VARCHAR(2000) FOR BIT DATA, for
exmaple.
What to do for BLOB columns ?

Best regars,
       Kovi

Signature

____________________________

|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Knut Stolze - 26 Aug 2007 17:24 GMT
>>>> Hi!
>>>>
[quoted text clipped - 17 lines]
> exmaple.
> What to do for BLOB columns ?

I just use prepared statements for those.

But you should still be able to convert the binary data to its hex
representation and then use the above INSERT statement as is. However, you
have to be aware that the hex representation is a string literal to the SQL
compiler and must not exceed the length limits.

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

4.spam@mail.ru - 27 Aug 2007 15:30 GMT
> Tis works if the column is defined like VARCHAR(2000) FOR BIT DATA, for
> exmaple.
> What to do for BLOB columns ?

INSERT INTO table(id, bytes) VALUES (1, blob(x'3334') )
Gregor Kovač - 30 Aug 2007 18:50 GMT
>> Tis works if the column is defined like VARCHAR(2000) FOR BIT DATA, for
>> exmaple.
>> What to do for BLOB columns ?
>
> INSERT INTO table(id, bytes) VALUES (1, blob(x'3334') )

Thank you both. :))
This is what I've been looking for.

Signature

____________________________

|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
|  In A World Without Fences Who Needs Gates?   |
|              Experience Linux.                |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.