java - Catch truncation errors -


i have small application embedded database. truncation errors when trying insert varchars exceeds maximum size of corresponding database column.

i wish detect before insert/updating , show correct message user.

now presume there 2 possibilities achieve this.

  1. get maximum length of column of interest through databasemetadata object. reduce performance lack using singletons or similar constructions.

  2. keep maximum lengths in java code (eg: in resourcebundle or properties file) , check against these values. downside off course java code , database must in sync. error prone.

what best approach?

the answer won't require maintenance getting maximum length of column of interest @ database connect time.

if use integer.valueof(...) can store in object, lower values (according current jvm specs) backs singleton pool anyway. unload lot of memory performance issues, columns refer few unique values have in database.

also, digging around in databasemetadata, flags indicate columns truncated upon larger data inserts. may provide switch know if code needed.

by putting values in property file, ease detection of issue, @ cost of possibly getting them out of sync. such techniques quick implementations little up-front cost, create latent issues. whether issue ever gets raised unknown, given enough time, remote possibilities encountered.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -