🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #2877

Problem storing binary data into MS Access

#2877
From: Kresimir TONKOVIC
Date: Thu, 10 Jun 1999 00:00
52 lines
3337 bytes
Hi!

I need to store some binary data in a MS Access database field.

The obvious way is to open the right row in a recordset and update
the field programatically, but the JDBC-ODBC bridge does not support
updateable recordsets.

The next idea was to prepare an UPDATE statement (PreparedStatement) and
set the data field using setBytes. This didn't work because no matter how
benign binary data I give, MS Access returns me an SQLException saying:

[Microsoft][ODBC Microsoft Access 97 Driver]Invalid precision value

whenever I call setBytes on a PreparedStatement. This worked well with 
MS SQL Server, but Access is an entirely different story.

The next thing was to try to use setString on the PreparedStatement with
the String containing my binary data but...

JDK 1.2.1 Strings are bloody $&#% clever and ALWAYS do some stupid
conversions. I tried to avoid these conversions in many ways but none
worked well because when ByteToCharConverters see a character that is 
undefined for the encoding, it converts it into a '?'. Everybody is
used to seing boxes in place of undefined characters, so I can't see
who would find these '?'s useful.

Here are some methods I tried:

- I tried all SingleByte converters. None do well for me
- I preencoded the byte array into a UTF-8 sequence that would result
  in a correct sequence of chars. However, I again got '?' in places 
  of 127, 128, 129...
- I wrote a ByteToChar converter that would do the trick, but I
  couldn't make String to use it. In vain I even altered the
  font.properties file to use my converter, but it didn't work (I'm not
  surprised about that one - I tried it in vain).
- I tried many other things, which I don't mention because they were not
  supposed to work anyway when I look back.

Ideas like "base64 encode the data and store it" and such won't work for me
because the data must be compatible with legacy programs that use it.

Altogeher, the closest result was using the default (CP1252) converter, 
because it was good for all but 6-7 values above 128. All other converters
ruined more values.

Thanks for any help.

-- 
Kresimir Tonkovic
kresho@ieee.org
Technical Details
Message-ID: <7jo5ug$c7n$1@bagan.srce.hr>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f5d71,a5b883f47764ef6,start
X-Google-Attributes: gidf5d71,public
X-Google-Thread: 1089d0,a5b883f47764ef6,start
X-Google-Attributes: gid1089d0,public
X-Google-Thread: f74b3,a5b883f47764ef6,start
X-Google-Attributes: gidf74b3,public
X-Google-Thread: fecd1,a5b883f47764ef6,start
X-Google-Attributes: gidfecd1,public
X-Google-Thread: 10a146,a5b883f47764ef6,start
X-Google-Attributes: gid10a146,public
X-Google-Thread: 107d55,a5b883f47764ef6,start
X-Google-Attributes: gid107d55,public
From: Kresimir TONKOVIC <ktonkov@diana.zesoi.fer.hr>
Subject: Problem storing binary data into MS Access
Date: 1999/06/10
Message-ID: <7jo5ug$c7n$1@bagan.srce.hr>
X-Deja-AN: 488063593
X-Complaints-To: news@news.carnet.hr
X-Trace: bagan.srce.hr 929012496 12535 161.53.64.5 (10 Jun 1999 11:01:36 GMT)
Organization: FER
User-Agent: tin/pre-1.4-980226 (UNIX) (SunOS/5.6 (sun4c))
NNTP-Posting-Date: 10 Jun 1999 11:01:36 GMT
Newsgroups: borland.public.jbuilder.java.api,borland.public.jbuilder.java.language,comp.lang.java,comp.lang.java.api,comp.lang.java.programmer,comp.lang.java.tech