Link to home
Start Free TrialLog in
Avatar of raghava_dg
raghava_dg

asked on

ResultSet.getString truncating the column value of Sybase

Hi ,

I have a column of varchar(1500) in a table (in sybase 12.5) .
When ever I do rs.getString("columnName") , I get only 256 characters . I am not receving all the characters in the column .

Is this limitation of Sybase Driver ? (jconnect driver) ? . Is there any way I can get complete data ? Please advice ASAP .

Thanks for advice.
Raghav
Avatar of aozarov
aozarov

Avatar of raghava_dg

ASKER

Ok . Then I need to convert the Clob to string is it ?
I will try this option .

Thanks
Raghava
Change the datatype of the field as "test" and then try

U can get only 256 chars if u declare the type as varchar
Avatar of CEHJ
Try

StringReader value = new StringReader(resultSet.getCharacterStream("columnName"));
System.out.println(value.toString());
I think Sybase has historical limit storing more than 255 chars in VARCHAR . For your case, I will recommend using CLOB.

From my experience, once the field type is set to TEXT(CLOB), with the newest driver, getString will work perfectly.

 
aozarov  ,

CLOB is not supported in jconnect driver . So I can't use .

CEHJ ,

StringReader does not work . There is no constructer which takes Reader as argument .

I tried BufferedReader which takes Reader as constructer . But again same problem . I can not convert that back to string , if I tried to do BufferdReader.readLine()  I am getting 256 characters .

Guyz Any other ideas ?
Are you sure that your problem is with reading it truncated and not writing it truncated?
Did you check the content of that column using some other (non jdbc) tool?
>>There is no constructer which takes Reader as argument .

True. Try:


Reader in = resultSet.getCharacterStream("columnName");
StringBuffer sb = new StringBuffer(1500);
int buf = -1;
while((buf = in.read()) > -1) {
      sb.append((char)buf);
}
in.close();
System.out.println(sb);
aozarov ,

Yes my problem is while reading . I have the data more than 256 char in the column .

CEHJ ,

I tried ur suggestion . But still no luck :( . Looks like even getCharacterStream is unable read more than 256 chars . I mean this might be a prob with Sybase JDBC drive (jconnect Version 12.5)

any advice on this appriciated .

Do you mind to try a newer jconnection version -> http://www.sybase.com/detail?id=1009726 
That site also have a link to the jConnection discussion forum -> news://forums.sybase.com/sybase.public.jconnect
which I think will be a good place to find an answer to this question.
Changing the driver at this point is not possible . I may have to look into some other option :(
Did you try submitting your question to the forum mentioned above?
i tried clicking on that link but its not opening . It asks for some exe to open the forum page . Are you able to access that ?  Please let me know .
Yes, I am using Windows IE and it opens outlook with that specific news group.
You can access it thru here as well: http://groups-beta.google.com/group/sybase.public.jconnect
raghava_dg ,

see, I am working in Sybase only

u can not take more than 256 characters if u r not changing the Table field varchar(1500) as 'test'

test type will accept upto 2GB size of data and u can read the data by just

resultset.getString("TABLE_COLUMN_NAME").trim());

I given this solution already
ASKER CERTIFIED SOLUTION
Avatar of Madhavan Sundarraj
Madhavan Sundarraj
Flag of Saudi Arabia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes neo .

You are correct . After much R&D even I found out that I should change the column to Text .
Thanks for the suggestion . I will grant you the points .

I have already an application where it uses getString() methods every where. If I change column type now , I am worrying that it may break some where else .
If you came accross this anytime , can you let me know potential problems in changing the coulmn type of a table of an already existing application ?


Thanks
Raghava
So, you were able to save more then 256 characters (and I assume your verified that by reading the content somehow) but
without having the type of the column as TEXT the jdbc driver could not read more then 256 characters?
In Sybase, without having the type of the column as TEXT, the jdbc driver can not read more then 256 characters

If the type of the column is TEXT, u can save more than 256 characters and can retrieve too ...

aozarov :

>> and I assume your verified that by reading the content somehow

r u pointing out me??? If so, ur assumption is wrong and I faced the same problem in one of my project and I solved earlier in the same way

Raghava:

>>If I change column type now , I am worrying that it may break some where else .

Just changing the column type as TEXT and if u used getString to get the value it never give problem anywhere in ur program - I am sure about it :)

It's restriction with Sybase and not JDBC driver problem

Even, u can change such a restriction in Sybase too. For that, U should have Admin knowledge in Sybase to change those installation settings

Default sybase installation will not allow u to get more than 256 characters :)
neonlines,
>> r u pointing out me???
Definetly not :-)
I asked raghava_dg if he managed to write successfuly (not truncated) and I think his answer was yes (see his third reply).
Thank you for making it clear.
thankz aozarov ;)
Yes . I was able to store more than 256 characters bue retrival was the issue . By using TEXT we can solve this prob .

Thanks for every one for helping .