For example:
In MySQL. the data type Text,
If we have a column defined as Text in a MySQL table, when to retrieve value of this column in JDBC, you get the value with excess trailing spaces, you can call String#trim(), but if such column is intended to accept space characters (hit space key when input). What can I do then?
MySQL Text is only for example, please consider other similar data types in other database.
So, your question should be worded as: “How can I get rid of trailing spaces that my RDBMS puts into my fields?”
The answer is simple: never declare fixed-width columns such as CHAR(10) or NCHAR(10). These types were invented back in the dark ages of relational databases, and the only reason they still exist is for backwards compatibility with legacy systems.
Always use variable length width columns: VARCHAR, NVARCHAR, TEXT.
Now, if your columns are of variable width, and yet your fields contain trailing spaces, this means that you have converted your table from some older table which had fixed-width columns. There is nothing you can do other than read all of your fields, apply
String.Trim()to them, and write them back to the database.