File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Max length of string returned by Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Max length of string returned by Resultset" Watch "Max length of string returned by Resultset" New topic

Max length of string returned by Resultset

Bharathi Rajendran

Joined: Jan 10, 2007
Posts: 4
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?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19848

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

Joined: Jan 10, 2007
Posts: 4
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?
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
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

Sunil Kumar
Bharathi Rajendran

Joined: Jan 10, 2007
Posts: 4
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.
I agree. Here's the link:
subject: Max length of string returned by Resultset
It's not a secret anymore!