473,836 Members | 2,179 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 29909
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
2091
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
2357
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
10903
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
4448
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
9810
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
9656
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
10821
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...
0
10527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10575
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
9358
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7774
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
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.