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

时间:2022-09-27 12:18:33

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);

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...
  • 如果编辑单元格存储了一个数字并且我给它一个字符串,该方法将返回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....
  • 如果编辑单元格必须与其他每个条目(唯一)不同,并且新对象与其他内容相同,则该方法也将返回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://接口DatabaseMetaData是一个很好的方法。有SQL命令方法吗?

****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...**

****编辑://我觉得结果集数据足够好了。但是,isUnique()方法在哪里?** edit:// isSigned()完成了这个?编辑://所以我只检查!isSigned()和isWritable()。那么数据库列条件怎么样?例如...... X必须超过3个字符...... **

1 个解决方案

#1


3  

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 under each this table:

不要使用Object,只需使用与相关数据类型相关联的类型。您可以在此处找到有关在每个此表下的某些DB数据类型应使用哪些Java对象类型的更多详细信息:

alt text http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.anc1.gif

alt text http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.anc1.gif

Alternatively, you can use DatabaseMetaData#getColumns() to figure the column information (column name, datatype, size, maxlength, nullable, etc).

或者,您可以使用DatabaseMetaData#getColumns()来计算列信息(列名,数据类型,大小,maxlength,可空等)。

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.

还有许多其他可能有用的方法,例如getIndexInfo()用于计算所有索引,getPrimaryKeys()用于计算PK,getExportedKeys()用于计算FK,等等。只需在整个DatabaseMetaData API中查找一下即可找到所需内容。

#1


3  

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 under each this table:

不要使用Object,只需使用与相关数据类型相关联的类型。您可以在此处找到有关在每个此表下的某些DB数据类型应使用哪些Java对象类型的更多详细信息:

alt text http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.anc1.gif

alt text http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/mapping.anc1.gif

Alternatively, you can use DatabaseMetaData#getColumns() to figure the column information (column name, datatype, size, maxlength, nullable, etc).

或者,您可以使用DatabaseMetaData#getColumns()来计算列信息(列名,数据类型,大小,maxlength,可空等)。

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.

还有许多其他可能有用的方法,例如getIndexInfo()用于计算所有索引,getPrimaryKeys()用于计算PK,getExportedKeys()用于计算FK,等等。只需在整个DatabaseMetaData API中查找一下即可找到所需内容。