aspose file tools*
The moose likes JDBC and the fly likes getString() does not retrieve String bigger than 255 characters  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getString() does not retrieve String bigger than 255 characters  " Watch "getString() does not retrieve String bigger than 255 characters  " New topic
Author

getString() does not retrieve String bigger than 255 characters

Sandeep P Parmar
Greenhorn

Joined: Oct 20, 2009
Posts: 5
Hi experts,
I am using java with Sybase as backend. I have a field in table which stores varchar of around 400 characters. Now when I am creating a resultset in java and calling resultset.getString(1), it only returns 255 characters and remaining characters are lost. As per my knowledge there is no restriction on getString() in terms of data retrieval, atleast not 255 characters.

Any solution to this? I have also tried using getObject() and getBinaryStream() instead of getString(), it retrieves same 255 characters.

Please help. Thank you.

-Sandeep Parmar
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

It's probably the JDBC driver that's truncated they data on the request. Take a look at the configuration options and documentation for the JDBC driver and see if there is a max character limit of some kind. Often times you can resolve such issues by increasing the maximum size the driver will handle by adding a parameter to the connection string.

You can also try reading the data as a stream and seeing if you get over 255 characters.


My Blog: Down Home Country Coding with Scott Selikoff
Sandeep P Parmar
Greenhorn

Joined: Oct 20, 2009
Posts: 5
The issue has been resolved. I added JCONNECT_VERSION=6 in following JDBC URL jdbc:sybase:Tds:mrf-dbr2-dev.com:5050/scenario?JCONNECT_VERSION=6 and it works. By default JCONNECT_VERSION is set as 5 which restricts the data limit to 255 characters. Thanks guys.
avijit majumder
Greenhorn

Joined: Sep 01, 2009
Posts: 15
hi
Sandeep Parmar
Yes boss there is no any restriction of character langth of
getString(1) method of java

i have already use this
A function of SQL returm a verchar(1000) . Which I retrive in java end just getString(1).

........ as an exam

CREATE FUNCTION `fn_Month_Bwt_Date`() RETURNS text
BEGIN

DECLARE monthstring VARCHAR(1000);

// do your code here

//--------------

RETURN monthstring;
END$$

DELIMITER ;


in java end
String query="select ...from fn_Month_Bwt_Date.."
.....................................
rs.getString(1);

its is working fine

_______________________________________________________
Avijit Majumder

Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

avijit majumder wrote:hi
Sandeep Parmar
Yes boss there is no any restriction of character langth of
getString(1) method of java


But there can definitely be a restriction on the JDBC driver, as I believe Sandeep discovered. Since JDBC drivers are often thought of as black boxes, there's really no reason to think any of them behave the same. In this case, getString() is a method executed by the JDBC driver against a class that implements a ResultSet, so it can do strange things as Sandeep saw.
Sandeep P Parmar
Greenhorn

Joined: Oct 20, 2009
Posts: 5
Hi guys,
Is it possible to retrieve the full String without changing JCONNECT_VERSION to 6? I have restriction in project which limits me to use JCONNECT_VERSION=5.

Any solution?
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

As you saw in your tests, not really. You can try reading the data as a stream instead of getString but that's not likely to work. You could also try using 'clever' SQL string functions to cut up the text in the query although the performance of that is liable to be awful.

This is one of those situations you either need to demand to use JCONNECT_VERSION=6 or tell them no table can have a column larger than 255 characters. There's really no in-between (can't make gold from lead anyway)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getString() does not retrieve String bigger than 255 characters