检查编辑对数据库 ms-access 是否有效
我希望能够检查是否可以使用新对象编辑数据库中的单元格
示例方法声明:
something.isValid(Object newObject, row, column);
示例情况:
- 如果编辑单元格存储一个数字 我给它一个字符串,方法 将返回 false...
- 如果编辑 细胞必须与每个细胞不同 其他条目(唯一)和新对象是 和其他东西一样,方法 也会返回 false...
我的主要目标... 我想检查整行,如果一切都有效,我将编辑整行。
现在,我可以确定是否可以真正编辑某些内容的唯一方法是实际编辑它并查看是否出现错误。
edit://Interface DatabaseMetaData
是一个很好的方法。有没有SQL命令的方法?
****edit://我觉得resultsetmeta数据已经足够好了。但是, isUnique() 方法在哪里?** edit://isSigned() 可以完成此操作吗? edit://所以我只检查 !isSigned() 和 isWritable() 是否。数据库列条件怎么样?例如... X 必须超过 3 个字符...**
I want to be able to check if I can edit a cell in a database with a new object
Example method declaration:
something.isValid(Object newObject, row, column);
Example cases:
- If the editing cell stores an Number
and I give it a String, the method
will return false... - If the editing
cell has to be different than every
other entry (unique) and the new object is the
same as something else, the method
will also return false....
My main goal...
I want to check a whole row, and if everything is valid, I will edit the whole row.
Right now, the only way I can find out if I can actually edit something is by actually editing it and seeing if I get an error.
edit://Interface DatabaseMetaData
is a good method. Is there a SQL command method?
****edit://I feel like the resultsetmeta data is good enough. however, where is the isUnique()
Method?** edit://isSigned() accomplishes this?
edit://So I just check if !isSigned() and isWritable(). What about database column conditions? For example... X has to be more than 3 characters...**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用
Object
,而只使用与相关数据类型关联的类型。您可以在此处找到更详细的信息有关应将哪些 Java 对象类型用于某些数据库数据类型的信息,其中包括此表:(来源:oracle. com)
或者,您可以使用
DatabaseMetaData#getColumns()
到计算列信息(列名称、数据类型、大小、最大长度、可为空等)。还有很多其他方法可以使用,例如
getIndexInfo()
计算所有索引,getPrimaryKeys()
来计算 PK,getExportedKeys()
来计算 FK 等。只需稍微了解一下
DatabaseMetaData
API 找到您需要的。Don't use
Object
, but just use the type which is associated with the datatype in question. You can find here more detailed information about which Java object types you should be using for certain DB datatypes with among others this table:(source: oracle.com)
Alternatively, you can use
DatabaseMetaData#getColumns()
to figure the column information (column name, datatype, size, maxlength, nullable, etc).There are lot of other methods which may be of use, e.g.
getIndexInfo()
to figure all indexes, thegetPrimaryKeys()
to figure the PK's, thegetExportedKeys()
to figure the FK's, etcetera. Just poke a bit round in the wholeDatabaseMetaData
API to find that you need.