File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Only 256 chars stored in DB field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Only 256 chars stored in DB field" Watch "Only 256 chars stored in DB field" New topic
Author

Only 256 chars stored in DB field

Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
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

Joined: Feb 14, 2006
Posts: 121
Annoyingly resurrected!

Anyone know how to solve my 256 chars nightmare?
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Only 256 chars stored in DB field
 
Similar Threads
Software caused connection abort: socket write error
Default varchar length is 255, not 256. Why ?
Formatting xml using java
Showing special characters
Size for Prepared Statement setString()