473,809 Members | 2,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

INSERT binary data

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 PreparedStateme nt and setBlob/setBytes method?

Best regards,
Kovi

--
_______________ _____________
|http://kovica.blogspot .com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Aug 24 '07 #1
6 29897
Gregor Kovač wrote:
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 PreparedStateme nt and setBlob/setBytes method?
You can do this:

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

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Aug 24 '07 #2
Knut Stolze wrote:
Gregor Kovač wrote:
>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 PreparedStateme nt and setBlob/setBytes method?

You can do this:

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

--
_______________ _____________
|http://kovica.blogspot .com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Aug 24 '07 #3
Gregor Kovač wrote:
Knut Stolze wrote:
>Gregor Kovač wrote:
>>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 PreparedStateme nt and setBlob/setBytes method?

You can do this:

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
Tis works if the column is defined like VARCHAR(2000) FOR BIT DATA, for
exmaple.
What to do for BLOB columns ?

Best regars,
Kovi

--
_______________ _____________
|http://kovica.blogspot .com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Aug 25 '07 #4
Gregor Kovač wrote:
Gregor Kovač wrote:
>Knut Stolze wrote:
>>Gregor Kovač wrote:

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 PreparedStateme nt and setBlob/setBytes method?

You can do this:

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) .

Tis works if the column is defined like VARCHAR(2000) FOR BIT DATA, for
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.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Aug 26 '07 #5
>
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') )

Aug 27 '07 #6
4.****@mail.ru wrote:
>>
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.

--
_______________ _____________
|http://kovica.blogspot .com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Aug 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2090
by: David List | last post by:
I am wondering what I miss to be able to handle binary data from the mysql client. I have ensured that the user has file_priv set to 'Y' and that max_allowed_packet is larger that the binary lumps handled. Here is my version: Ver 4.1.5-gamma-log for pc-linux on i686 (Source distribution) Right now I'm trying this to insert binary data: mysql> update table set col=load_file("/path/file") where id=1;
0
1389
by: JC | last post by:
I'm converting a vb6 project to vb.net. I was able to insert a binary object into my XMLDOM using " Set oElement = xmlDoc.createElement("eDocument") oRoot.appendChild oElement oElement.dataType = "bin.base64" oElement.nodeTypedValue = (sPathToDoc) .....Now in .NET using the XML.XMLDocument DOM Model I'm not sure what to do. The code above does not 'convert'.
0
2355
by: Wescotte | last post by:
I'm abit confused on how to work with binary data with an ODBC connection (My database is DB2 btw) Say I have a table like CREATE TABLE EJWLIB.BLOBTEST ( ID NUMERIC(5) NOT NULL, FILENAME VARCHAR(128) NOT NULL, BINARY BLOB(2M) ) Now I (I assume this is the correct method) insert data in the
2
1241
by: supranoob | last post by:
I would like to wrap xml data/information around a file. Is it possible to insert binary data into an xml file? If so, where could I learn to do this? Thanks.
9
34147
by: Water Cooler v2 | last post by:
There are two datatypes for storing binary data type in the SQL Server: 1. binary - for fixed length binary data 2. varbinary - for variable length data My question is: how is data inserted into them? Do they have any delimiters that go into the insert statement like strings and datetimes have? What format (hex/decimal?) do they accept data in? Can you please give me an insert statement example?
0
1347
by: huiling25 | last post by:
This is how i insert binary data to a binary file: -> fingerprint is a BitSet format File binFile = new File("BinaryFp.txt"); FileOutputStream output = new FileOutputStream (binFile); DataOutputStream data = new DataOutputStream (output); for(int j=0,len=1024;j<len;j++) { boolean bit = fingerprint.get(j); data.writeBoolean(bit);
4
10896
multi
by: multi | last post by:
Hi all, my question is : is it possible to insert binary (like attachment) data into html, after that on client-side with javascript or ajax to get this data (download) from this html ?! give me some ideas, hints or anything :( Thank you !
0
4109
by: phoenix7 | last post by:
Dear all, I want to store some data in form of a zip file into an access database. I created a table with with a column of type OLE Object, then I designed a form to insert data to the table. I inserted some files to it, but when I tried to read them using my java client it retrieves an OLE object but I just need the file content (what the program gets form the db was the original file added with some extra binary information at the...
1
4447
by: chandrasrreddy | last post by:
Hello, I have lots of binary data. I would like to use Bulk insert to get this binary data into microsioft sql server database. Is this possible? If yes, how would I specify a delimiter for binary data? If someone has done this before, any information on how to do this would be much appreciated.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.