检查编辑对数据库 ms-access 是否有效

发布于 2024-08-29 22:59:33 字数 604 浏览 2 评论 0原文

我希望能够检查是否可以使用新对象编辑数据库中的单元格

示例方法声明:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-09-05 22:59:33

不要使用Object,而只使用与相关数据类型关联的类型。您可以在此处找到更详细的信息有关应将哪些 Java 对象类型用于某些数据库数据类型的信息,其中包括此表:

alt text
(来源:oracle. com)

或者,您可以使用 DatabaseMetaData#g​​etColumns() 到计算列信息(列名称、数据类型、大小、最大长度、可为空等)。

还有很多其他方法可以使用,例如 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:

alt text
(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, the getPrimaryKeys() to figure the PK's, the getExportedKeys() to figure the FK's, etcetera. Just poke a bit round in the whole DatabaseMetaData API to find that you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文