Article View: borland.public.jbuilder.java.api
Article #861Re: how to convert from datatype String into datatype Blob
From: Shankar Unni
Date: Wed, 09 Oct 2002 17:10
Date: Wed, 09 Oct 2002 17:10
31 lines
2302 bytes
2302 bytes
On 10/9/2002 2:15 AM, andy wrote:
> can convert from String into a Blob variable ?
This is for what? For passing to PreparedStatement.setBlob()?
Creating Blob objects is _completely_ implementation-defined. Many JDBC
implementations don't support this at all (e.g. mm.mysql), or make it
very convoluted (e.g. Oracle, where you have to first create a BLOB
object in the DB, and then map it to memory).
What you *can* do with the String is one of the following (and even with
these, there are implementation issues):
1. PreparedStatement.setBytes(column, string.getBytes())
2. PreparedStatement.setBinaryStream(column,
new ByteArrayInputStream(string.getBytes());
3. Use a platform-specific sequence to get a Blob object (read your
particular JDBC driver's documentation) and call
PreparedStatement.setBlob().
For instance,
1. works in Oracle for strings upto 32000 bytes, and in MySQL for all
strings.
2. works in Oracle as long as you are using the thick driver, or the
thin driver version later than 9.2.1.
3. doesn't work at all for MySQL, and is extremely convoluted for Oracle.
--
Shankar.
Technical Details
Message-ID:
<3DA462F9.1080503@cotagesoft.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news.he.net!news-out.spamkiller.net!propagator2-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3da3f3b4@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,ca43bfe29e6e3c74 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2002-10-09 10:22:05 PST Message-ID: <3DA462F9.1080503@cotagesoft.com> Date: Wed, 09 Oct 2002 10:10:17 -0700 From: Shankar Unni <shankar@cotagesoft.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 (Compact) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api Subject: Re: how to convert from datatype String into datatype Blob References: <3da3f3b4@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 64.165.207.58 X-Trace: newsgroups.borland.com 1034183463 64.165.207.58 (9 Oct 2002 10:11:03 -0700) Lines: 32 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news.he.net!news-out.spamkiller.net!propagator2-maxim!news-in.spamkiller.net!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail