aspose file tools*
The moose likes JDBC 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Max length of string returned by Resultset" Watch "Max length of string returned by Resultset" New topic
Author

Max length of string returned by Resultset

Bharathi Rajendran
Greenhorn

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
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

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

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
http://goodtoknowit.blogspot.com/
Bharathi Rajendran
Greenhorn

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: http://aspose.com/file-tools
 
subject: Max length of string returned by Resultset
 
Similar Threads
XML Data Mapping
Using ResultSet.getString( )
Strange problem with MySQL full text query
Replacing *.hbm.xml files with @Annotations.
Only 256 chars stored in DB field