Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Help: How to insert binary data into Oracle via JDBC?
Hi Mike! You guys (Cisco) are customers of ours! Check out our example directory under jdbc/oracle. There's plenty of examples, including this issue. If you're in a group not using WebLogic, download our stuff for free, if only to get the examples! In general, the method is to use a PreparedStatement and do setBinaryStream() and getBinaryStream()... Joe Weinstein at WebLogic, Inc.
Michael Zhao wrote:
> Hi,
>
> I'm trying to insert and get binary data into/from oracle database via JDBC
> in Java. I have a simple table and a stored procedure for insert, use normal
> JDBC api to get data.
>
> Anyone knows how to insert/get BINNARY data by using JDBC? Hex code as in 1
> & 2 below, or uuencode is not what I want.
>
> It seems that no method can handle '\0' in binary data.
>
> Any suggestion is highly appreciated.
>
> -Michael
>
> ----------------------
> My_tab (
> Id number(5,0);
> Data long;
> )
>
> Stored procedure myinsert(id in integer, dat in varchar2 ( or long) )
>
> I tried following methods in java.sql.PreparedStatement to insert binary
> data, none worked:
>
> i.e.
> byte[] mydate={ 'A','B','\0','C','D'};
>
> 1. setBinaryStream(int, InputStream, int)
>
> problem: "AB" become "4142" in db.
>
> 2. setBytes(int, byte[])
>
> problem: Same as 1.
>
> 3. setAsciiStream(int, InputStream, int)
>
> problem: Only "AB" was inserted into db.
>
> 4. setString(int, String)
> str = new String(mydata)
> setString(2,str);
>
> problem: Same as 1.
-- Joseph Weinstein Staff Engineer http://www.weblogic.com See our newsgroups: http://www.weblogic.com/services/newsgroups.html try weblogic free *with support*: http://www4.weblogic.com/register.htmlReceived on Thu Aug 20 1998 - 00:00:00 CDT