Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: ODBC Error: String Literal to long?

Re: ODBC Error: String Literal to long?

From: Richard Grover <grover_at_gdt-inc.com>
Date: Tue, 07 Sep 1999 12:16:57 -0700
Message-ID: <37D564A9.A70FA483@gdt-inc.com>


I found what I was doing wrong with Long datatypes and JDBC... errrrr, at least I've been able to make it work.

I was trying to insert rows using a text literal of 'abc...xyz' greater than 2K...at least in JDBC the max char literal is 2K (from what I understand oracle 7 treats text literals as VARCHAR2 which has a max 2K size). At any rate, this caused my insert to fail because the specified literal was greater than 2K. Apparently the proper way to insert Long data using JDBC is through a prepared statement and an Ascii Input Stream.

I hope this is of some use.

Sample Code...

     create table streamexample (data long)

    PreparedStatement pstmt = conn.prepareStatement ("insert into streamexample values (?)");

     InputStream is = new FileInputStream ("notes.txt");
     File file = new File ("notes.txt");
     pstmt.setAsciiStream (1, is, (int)file.length ());

    ResultSet rset = stmt.executeQuery ("select * from streamexample");

     InputStream ascii_data = rset.getAsciiStream (1);
     // Loop, reading from the gif stream and writing to the file     int c;
     while ((c = ascii_data.read ()) != -1)
         System.out.print(c);

Richard Grover wrote:

> I am experiencing a similar problem with JDBC/ODBC to oracle 7 storing a large
> string into a LONG field...what I've read in the doc's seems to indicate that
> this is due to a buffer sizing issue...but what buffer and how to size it
> escapes me?
>
> Rich G.
>
> --------------------------------------------------------------
>
> Chris Bos wrote:
>
> > Hi,
> >
> > whenever I try to insert a string that is larger than 2000 characters into
> > an oracle LONG field via ODBC I get an eror telling me the string literal is
> > to long.. can anyone explain the why and possible solution to me? I am using
> > oracle 7.3 on NT and VB to do the inserts.
> >
> > Thanks
> > Chris Bos
Received on Tue Sep 07 1999 - 14:16:57 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US