• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Max length of string returned by Resultset

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All, Am using Sybase DB and retrieve data into Java code.I have a column of type "text" and return a variable of length 300 chars to Java from the "text" field.
Java uses resultset.getString("column name") to get the column's value from the result set.

The issue we have is - even if the DB returns a value of length 300 chars, java is truncating it to 255. Same is the case when tried with resultset.getObject("column name").toString().

Is there any limit on the string length returned by Result set? Is there any way to maximise / set the length of string returned from result set?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the Java side, there is no restriction on the length of Strings (unless you want Strings which are more than 2 billion characters long). On the database side, it's quite common for a database to put limits on the length of text columns. 255 is a common limit for that.

Once the database has truncated the string, though, there is no way to repair it. Not in Java nor in the database. There are other column types which allow longer strings to be stored, so you should consider using them instead.
 
Bharathi Rajendran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul.

We are using BEA Sybase driver and the Sybase Table has this column as a "Text" Field which allows upto 2GB. The fact is, when we run the Stored Procedure in the DB we get the complete text without truncating to 255 chars. But when we call the Stored proc from Java code using JDBC, the resultset.getString() truncates it to 255. I wonder whether this is an issue with JDBC.

Any pointers on this?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try retrieving data as Clob/Blob (i.e. stream).
Further if there is no limit imposed on the table schema, check for Statement.getMaxFieldSize in your code whether or not you are applying a limit on the retrieval size
 
Bharathi Rajendran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Sunil.

But I tried setting the MaxFieldSize to 300.It was defaulted to 0 earlier.
Even after this , I do see only 255 chars in the resultset returned from Sybase to Java.
I tried to retrieve it as an Object instead of a String. But again, in vein.
 
reply
    Bookmark Topic Watch Topic
  • New Topic