VARCHAR does not work as expected in Apache Derby

Posted by Tom Brito on Stack Overflow See other posts from Stack Overflow or by Tom Brito
Published on 2010-05-18T15:34:33Z Indexed on 2010/05/18 15:41 UTC
Read the original article Hit count: 352

Filed under:
|
|
|
|

I'm having this same problem:

How can I truncate a VARCHAR to the table field length AUTOMATICALLY in Derby using SQL?

To be specific:

CREATE TABLE A ( B VARCHAR(2) ); INSERT INTO A B VALUES ('1234'); would throw a SQLException:

A truncation error was encountered trying to shrink VARCHAR '123' to length 2.

that is already answered:

No. You should chop it off after checking the meta-data. Or if you don't wanna check the meta-data everytime, then you must keep both your code and database in sync. But thats not a big deal, its a usual practice in validators.

but my doubt is: isn't VARCHAR suppose to variate its size to fit the data? What's wrong with apache derby's VARCHAR?

© Stack Overflow or respective owner

Related posts about java

Related posts about apache