• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Only 256 chars stored in DB field

 
Alana Sparx
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm committing a String to a SqlServer database field. Problem is that the field is only storing the first 256 chars of the String. I initially set the field to a VARCHAR of 500, but still only 256 chars committed. I then set the db field value to be TEXT - still only accepting 256 chars.

I'm spitting the string out into the logs shortly before executing the PreparedStatement, and it prints into the log fine. Any ideas, folks?

Many thanks
As
 
Scott Selikoff
author
Saloon Keeper
Posts: 3889
15
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database are you using and what is your character encoding? At the very least you should get a truncation error or a general error of some kind. Sometimes if the encoding is set wrong, it may store each character as 2-3 bytes but this usually is a limit that happens closer to 2k and 256 should be just fine. Also, attach your code so we can take a look.
 
Alana Sparx
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott

Character Encoding? No idea, how do I find this out? I'm making the assumption this is some default value?

The database is SqlServer 2000.

The code is:

the payload parameter is an XML String representing an object fed through an XML utility class that ultimately uses Castor. If I print this String out prior to preparing the sql statement, it looks fine, all the tags and data are contained inside it. But, when it's fed into the database, only the first 256 chars are there - there is no truncation error in the log!

I expect that this is some SqlServer2000 issue, so appreciate that this forum may not be the correct place for it, but, dammit, I'm desperate!

Thanks for any light you can shed on this.

As
 
Alana Sparx
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annoyingly resurrected!

Anyone know how to solve my 256 chars nightmare?
 
Alana Sparx
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a LOSER!!!

Next time I'll check the Sql Query Analyser, and make sure the display option is not set to 256 chars when executing statements.

Is there anything MS does that isn't utterly shit by default?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic