Link to home
Start Free TrialLog in
Avatar of stevieaj99
stevieaj99

asked on

JDBC - ODBC getBinaryStream returns only 255 characters from MS Access Memo field

Hi,

I am trying to get a memo field value from MS Access using a getBinaryStream. At the moment it will only return 255 characters - no more than a standard getString.
The memo field value has 260 characters. Basically, the code returns the first 255 then returns -1.
I am using JDK1.3 with Jbuilder7. MS Access 2000 database format. The JDBC to ODBC driver. Windows XP Pro. Latest ODBC as per MS site.

The code is ...

try{

    InputStream dbin = rs3.getBinaryStream("DetailedAlertDescription" );
    for( int xread; ( xread = dbin.read() ) != -1; )
    {
        String C = String.valueOf(xread);
        LogSession.OutputLog_Message( C );
    }
}catch(Exception e) {e.toString(); };

Help...
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why are you not using getString()

?
Avatar of stevieaj99
stevieaj99

ASKER

The real length of data I want to store in this memo field is > 4K. The Test data was set to 260 to prove it would not work. getString according to the JDBC spec will only return < 255 characters.
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland 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
OK - tried the code. Had to change getChracterStream line to

Reader in = rs3.getCharacterStream("DetailedAlertDescription");

And the same thing happens. Only 254 characters are returned from the memo field (this has 260).

?
Are you *certain* that it's a memo field and not a normal string?
I have just double checked. It is a memo field. It has 260 characters in the first record.

Just to humour me, please post


System.out.println(rs3.getMetaData().getColumnTypeName(n);

(where 'n' is the 1-indexed index of "DetailedAlertDescription")

OK.

This is the query for the result set.

QueryAlertDesc = "SELECT DISTINCT SITEALERTS.SiteID, SITEALERTS.AlertCode, SITEALERTS.AlertSubCode, ALERTS.AlertDescription, ALERTS.DetailedAlertDescription, SITEALERTS.LocalAlertDescription, SITEALERTS.DetailedLocalAlertDescription, ALERTS.PhraseNo FROM ALERTS INNER JOIN SITEALERTS ON (ALERTS.AlertSubCode = SITEALERTS.AlertSubCode) AND (ALERTS.AlertCode = SITEALERTS.AlertCode) WHERE (((SITEALERTS.AlertCode)='" + AlertCode + "') AND ((SITEALERTS.AlertSubCode)='" + AlertSubCode + "') AND ((SITEALERTS.SiteID)='" + SiteID + "'));";

The metadata values returned are ...

VARCHAR = SiteID
VARCHAR = AlertCode
VARCHAR = AlertSubCode
VARCHAR = AlertDescription
LONGCHAR = DetailedAlertDescription
VARCHAR = LocalAlertDescription
LONGCHAR = DetailedLocalAlertDescription

I'lll have to think about this ..;-)
Try using getAsciiStream()
ASKER CERTIFIED SOLUTION
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
OK this is what I did.

Tried getAsciiStream first and it didn't work.

Simplified query and I was able to use a getString to get all the data.

I was also able to use the getAsciiStream, getCharacterStream and getBinaryStream!

Does any one know why?
The problems with Access by the sounds, and its not handling the query correctly.
Try slowly building up your query until you find what specificqalluy is causing the problem.
Do you get any indications of anything amiss when you try this outside Java?
I have broken this down into a complex query without DISTINCT and JOIN - still doesn't work.
I have removed DISTINCT and the JOIN on their own - still doesn't work.
In order words keep it simple stupid is the overall principle (thats aimed at me not you).

Tried this in access and its ok as a complex query - no surprise there.

Not tried it in VS 2003/2005 under VB.NET or C#.Net.  Next step would be a proper JDBC type 3 driver as the app is growing by the day and its time I upgraded - just need to find a good one in the next week or so.

>>.  Next step would be a proper JDBC type 3 driver

That would be interesting
Or use a decent db :)

using a type 3 driver would very likely fix the problem, but there aren't many around for access.
Yep...been putting off upgrading to SQL and a good JDBC but I need to face the facts.
8-)
Glad I could help you find the cause of your problem :)
Let me know if you need any further help.