I've got a small application by having an embedded database. Sometimes Is get truncation errors when attempting to place varchars which surpasses the utmost size the related database column.

If only to identify this before place/upgrading and show a proper message towards the user.

Now I presume that you will find two options to do this.

  1. Get the most entire column of great interest with the DatabaseMetaData object. You can lessen the performance lack by utilizing Singletons or similar buildings.

  2. Keep your maximum measures within the Java code (eg: in ResourceBundle or Properties file) and appearance against these values. Bad thing is off beam that Java code and database should be synchronized. This really is error prone.

What will be the ultimate way?

The only real answer that will not require maintenance gets the utmost entire column of great interest at database connect time.

If you are using Integer.valueOf(...) you are able to store this within an object, that the lower values (based on the current JVM specs) backs to some singleton pool anyway. This can unload lots of memory performance issues, as all of the posts will ultimately make reference to the couple of unique values you have in all probability inside your database.

Also, digging around within the DatabaseMetaData, I'd search for any flags that indicate that posts could be cut down upon bigger than data card inserts. It might supply the change to determine if your code is required.

By putting the values inside a property file, you ease the recognition from the problem, but at the expense of possibly providing them with from sync. Such techniques are effectively quick implementations with little up-front cost, however they create latent issues. If the problem ever will get elevated is going to be unknown, but given sufficient time, the remote options are experienced.

Mixture of both approaches. Throughout application build time, you utilize DatabaseMetaData to dynamically produce a resource bundle.

One solution is always to make use of a CLOB. I'm not sure the other needs you've with this area.

Also, Make use of the littlest max character value you've like a constant within the java code. This handles it needing to maintain sync or db dependent and it is pretty much arbitrary anyway. Customers don't care exactly what the max dimensions are, they simply need to understand what the max dimensions are or perhaps be stored from making a mistake instantly.