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.
Asked
Active
Viewed 388 times
-2
-
1What is the exception which is thrown and its message? It might be trying to tell you something. ;) – Peter Lawrey Jan 10 '12 at 10:35
-
use e.PrintStacktrace() inside the catch block to see the error – Count Jan 10 '12 at 10:41
1 Answers
1
Seems you try to insert balnk value ("") into the date field. Insert null value instead.

Bon Espresso
- 693
- 3
- 5
-
Thank you for taking your time to answer. I discovered where the problem was. I'd set a validation to the text field which added strange characters when left blank, which of course where not accepted by the BD when the format was "date/time". **e.PrintStacktrace()** didn't work here, but it was very useful in another project I had problems with. This time I used **System.out.println(query)** to see what the query was actually generating, and I could see my mistake. Thank you again. – user1140461 Jan 15 '12 at 16:40