PreparedStatment INSERT fails due to varchar records too big

PreparedStatment INSERT fails due to varchar records too big

Post by Alan M. Friedma » Fri, 10 Mar 2000 04:00:00



    I have a very large insert which fails due to the fact that all the
fields are padded to
full varchar size rather than packed to the actual length of the
records.

    I'm inserting records into a database and I find that when using
varchar
type fields, so as to conserve space, the records are apparently being
padded
to the full varchar size when created with a PreparedStatement using
JDBC.

            For example, if I create a table:

    CREATE TABLE  TestTable (Field1   varchar(40))

and then do an INSERT:

      INSERT INTO TestTable (Field1) VALUES ("Hello World")

. . . I find that if this insert is done with JDBC using a
PreparedStatement, the length of
the resulting record will be 40, not 11.  If the same insert is done
using a JDBC Statement, or
manually inserting in an SQL query analyzer, the record length will be
11.

    Can anyone tell me why PreparedStatements used in JDBC seem to pad
varchar
records to their full size???  Sort of defeats the purpose of using a
varchar types.  :-)

    Any clue would be gratefully appreciated.

Alan

 
 
 

PreparedStatment INSERT fails due to varchar records too big

Post by Geert Van Damm » Fri, 10 Mar 2000 04:00:00


I really think you'll need to specify which DBMS and especially which JDBC
driver you use before you can get a decent answer ;-)

Geert 'Darling' Van Damme



>    I have a very large insert which fails due to the fact that all the
>fields are padded to
>full varchar size rather than packed to the actual length of the
>records.

>    I'm inserting records into a database and I find that when using
>varchar
>type fields, so as to conserve space, the records are apparently being
>padded
>to the full varchar size when created with a PreparedStatement using
>JDBC.

>            For example, if I create a table:

>    CREATE TABLE  TestTable (Field1   varchar(40))

>and then do an INSERT:

>      INSERT INTO TestTable (Field1) VALUES ("Hello World")

>. . . I find that if this insert is done with JDBC using a
>PreparedStatement, the length of
>the resulting record will be 40, not 11.  If the same insert is done
>using a JDBC Statement, or
>manually inserting in an SQL query analyzer, the record length will be
>11.

>    Can anyone tell me why PreparedStatements used in JDBC seem to pad
>varchar
>records to their full size???  Sort of defeats the purpose of using a
>varchar types.  :-)

>    Any clue would be gratefully appreciated.

>Alan



 
 
 

PreparedStatment INSERT fails due to varchar records too big

Post by Alan M. Friedma » Fri, 10 Mar 2000 04:00:00


            My apologies. :)

    I'm using MS SQL as a database and I'm using Sun's jdbc:odbc driver,
 "sun.jdbc.odbc.JdbcOdbcDriver", but I've also tried Microsoft's driver
 "com.ms.jdbc.odbc.JdbcOdbcDriver".  With the same results.

            Someone emailed me concerning the possibility of seeing the bug
detailed at:
http://developer.java.sun.com/developer/bugParade/bugs/4234356.html
...but this doesn't seem applicable, as I'm not getting a setString truncated,
I'm just
trying to insert a record with over 260 fields, all strings, several of which
may be as
long as 40 to 50 characters in length.  Since most of them average 10-15
characters
in length, using a varchar of 60 should allow for the longest records, with
the extra
space for a 10 char string not being used or wasted.  However, I find that
creating
a table with 270 fields, each defined as varchar 60, will occupy over 16,200
bytes
(270x60) well exceeding the 8,000 or so maximum for a single row in MS SQL.

        I've been trying to use a Statement instead of PreparedStatement, and
while
I have had extreme problems getting it to work with real data, I have
determined
that the same varchar problem doesn't seem to exist with a JDBC Statement.

            I'm also using JDK v1.2.2 which I don't believe has JDBC 2, so Im
going to try the latest JDBC 2 version next to see if it helps.

        Anyone else seen this or have any idea what's going on?

Thanks,
Alan


> I really think you'll need to specify which DBMS and especially which JDBC
> driver you use before you can get a decent answer ;-)

> Geert 'Darling' Van Damme



> >    I have a very large insert which fails due to the fact that all the
> >fields are padded to
> >full varchar size rather than packed to the actual length of the
> >records.

> >    I'm inserting records into a database and I find that when using
> >varchar
> >type fields, so as to conserve space, the records are apparently being
> >padded
> >to the full varchar size when created with a PreparedStatement using
> >JDBC.

> >            For example, if I create a table:

> >    CREATE TABLE  TestTable (Field1   varchar(40))

> >and then do an INSERT:

> >      INSERT INTO TestTable (Field1) VALUES ("Hello World")

> >. . . I find that if this insert is done with JDBC using a
> >PreparedStatement, the length of
> >the resulting record will be 40, not 11.  If the same insert is done
> >using a JDBC Statement, or
> >manually inserting in an SQL query analyzer, the record length will be
> >11.

> >    Can anyone tell me why PreparedStatements used in JDBC seem to pad
> >varchar
> >records to their full size???  Sort of defeats the purpose of using a
> >varchar types.  :-)

> >    Any clue would be gratefully appreciated.

> >Alan


 
 
 

PreparedStatment INSERT fails due to varchar records too big

Post by Alan M. Friedma » Sun, 12 Mar 2000 04:00:00


I just wanted to inform anyone interested that I've been able to
cure my varchar padding problems using a JDBC driver from
BEA Weblogic.  The driver name is:

     weblogic.jdbc.mssqlserver4.Driver

       Although this works great, I would still like to try to find a
JDBC or ODBC:JDBC driver which is available under Open Source
or might otherwise be in the Public Domain, but don't have this
varchar padding problem with Prepared Statements.

     Anyone know of any other available JDBC drivers I can try?

With thanks,
Alan


>             My apologies. :)

>     I'm using MS SQL as a database and I'm using Sun's jdbc:odbc driver,
>  "sun.jdbc.odbc.JdbcOdbcDriver", but I've also tried Microsoft's driver
>  "com.ms.jdbc.odbc.JdbcOdbcDriver".  With the same results.

>             Someone emailed me concerning the possibility of seeing the bug
> detailed at:
> http://developer.java.sun.com/developer/bugParade/bugs/4234356.html
> ...but this doesn't seem applicable, as I'm not getting a setString truncated,
> I'm just
> trying to insert a record with over 260 fields, all strings, several of which
> may be as
> long as 40 to 50 characters in length.  Since most of them average 10-15
> characters
> in length, using a varchar of 60 should allow for the longest records, with
> the extra
> space for a 10 char string not being used or wasted.  However, I find that
> creating
> a table with 270 fields, each defined as varchar 60, will occupy over 16,200
> bytes
> (270x60) well exceeding the 8,000 or so maximum for a single row in MS SQL.

>         I've been trying to use a Statement instead of PreparedStatement, and
> while
> I have had extreme problems getting it to work with real data, I have
> determined
> that the same varchar problem doesn't seem to exist with a JDBC Statement.

>             I'm also using JDK v1.2.2 which I don't believe has JDBC 2, so Im
> going to try the latest JDBC 2 version next to see if it helps.

>         Anyone else seen this or have any idea what's going on?

> Thanks,
> Alan


> > I really think you'll need to specify which DBMS and especially which JDBC
> > driver you use before you can get a decent answer ;-)

> > Geert 'Darling' Van Damme



> > >    I have a very large insert which fails due to the fact that all the
> > >fields are padded to
> > >full varchar size rather than packed to the actual length of the
> > >records.

> > >    I'm inserting records into a database and I find that when using
> > >varchar
> > >type fields, so as to conserve space, the records are apparently being
> > >padded
> > >to the full varchar size when created with a PreparedStatement using
> > >JDBC.

> > >            For example, if I create a table:

> > >    CREATE TABLE  TestTable (Field1   varchar(40))

> > >and then do an INSERT:

> > >      INSERT INTO TestTable (Field1) VALUES ("Hello World")

> > >. . . I find that if this insert is done with JDBC using a
> > >PreparedStatement, the length of
> > >the resulting record will be 40, not 11.  If the same insert is done
> > >using a JDBC Statement, or
> > >manually inserting in an SQL query analyzer, the record length will be
> > >11.

> > >    Can anyone tell me why PreparedStatements used in JDBC seem to pad
> > >varchar
> > >records to their full size???  Sort of defeats the purpose of using a
> > >varchar types.  :-)

> > >    Any clue would be gratefully appreciated.

> > >Alan


 
 
 

1. Update on large record set fails due to syslog fill

I have a table with ~250000 rows which I am trying to do a simple,
single field update (per TSQL below).  I can update a small number of
rows, <100, without any problem but as soon as I try updating in the
thousands, the update fails with an error message stating the syslog is
full.  Is this a server configuration problem/my query/or???

**T-SQL
UPDATE table1
SET field1 = 1

** Log Device is allocated 512MB of space.  The size of the log
allocation does not seem to matter since even when I increased it to
1GB, it still filled the entire space.

** I am truncating the log on checkpoint but since the update takes
place in one SQL statement, I don't think the checkpoint is occuring.

Any ideas?

Dong Soo Anderson-Song
Raybeam Solutions, Inc.

2. Remote Confusion - VFP 5.0

3. Syntax Error when adding a record using INSERT INTO (due to date field)

4. JKEY

5. How to Insert individual record when bulk insert failed

6. GetRows and BLOBs

7. DTS transfer INSERT FAILS error on VarChar NOT NULL column

8. error 17803- Pls Help

9. inserting a semicolon into a varchar record

10. Insert record failed

11. Using ADO Recordsets and ODBC fails to insert records with Unicode characters

12. Trigger fails when records inserted through ASP

13. Help: Transaction with insert many record failed in referential integrity