我有少量应用,有一个嵌入式数据库。 有时 在试图插入超出相应数据库一栏最高规模的斜体时,会出现拖网错误。
我希望在插入/更新之前发现这一点,并向用户发出正确的信息。
Now I presume that there are two possibilities to achieve this.
Get the maximum length of the column of interest through the
DatabaseMetaData
object. You could reduce the performance lack by using Singletons or similar constructions.Keep the maximum lengths in the Java code (eg: in
ResourceBundle
orProperties
file) and check against these values. Downside is off course that Java code and database must be in sync. This is error prone.
What would be the best approach?