“日期”时出错通过 Java 表单在 Access 2003 中字段为空
我正在制作一个基于 Access 2003 数据库的 Java 程序,用于保存美术馆的客户、联系人、艺术家、作品、展览等的所有数据。我在数据库中有几个字段需要存储日期,因此我将格式(在数据库字段中)设置为“日期/时间”。这些字段是“不需要的”,并且它们不是表中的主键(或辅助键或外键)。当我运行程序时,其他一切都工作正常,但出于同样的原因,如果我将表单中的“日期”字段留空,它不会保存整个表单中的任何内容并引发错误(它跳转到“捕获异常”行不保存任何东西)。如果我写了一个有效的日期,它就可以正常工作,我使用的格式并不重要(即它接受 2/5/2010、02/05/2010、2/5/10、2-5-2010)。 另外,如果我将数据库中的格式更改为“文本”,问题就会消失,如果我愿意,我可以将该字段留空。问题是我需要能够按日期进行搜索,因此格式很重要。有什么建议吗?我是Java和Access的初学者,所以这可能是我做错的一些愚蠢的事情,但这真的很烦人,因为它似乎没有任何逻辑。
I'm making a Java program based on an Access 2003 database to keep all the data of clients, contacts, artists, works, exhibitions, etc for an art gallery. I have several fields in the DB where I need to store dates, so I've set the format (in the DB fields) as "date/time". The fields are "not required", and they are not the primary (or secondary, or foreign) key in the table. When I run the program everything else works fine, but for same reason if I leave the "date" field in the form blank it doesn't save anything in the whole form and throws an error (it jumps to the "catch exception" line without saving anything). If I write a valid date, it works fine, it doesn't matter the format I use (i.e. it accepts 2/5/2010, 02/05/2010, 2/5/10, 2-5-2010).
Also, If I change the format in the DB to "text" the problem disappears, and I can leave the field blank if I want to. The thing is I need to be able to do searches by date, so the format is important. Any suggestions? I'm a beginner in both Java and Access, so it's probably something stupid I'm doing wrong, but it's really annoying, because it doesn't seem to have any logic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您尝试将空白值(“”)插入日期字段。
而是插入空值。
Seems you try to insert balnk value ("") into the date field.
Insert null value instead.