Results 1 to 4 of 4

Thread: Problem with a DA class

  1. #1

    Thread Starter
    Addicted Member ddmeightball's Avatar
    Join Date
    Nov 2004
    Location
    Nebraska
    Posts
    183

    Problem with a DA class

    I am having a problem with a DA class that I am writing. My problem seems to be stemming from when I try to put a date object into an Access database datetime field.

    I believe it is a problem with my insert sql statement. Here it is.

    Code:
    		String sql = "INSERT INTO SECTIONS(course_number, section_number, instructor_id, days, start_time, end_time, begin_date, end_date, room_number) values(" 
    		+ "'" + s.getCourseNum() + "'" + "," 
    		+	    s.getSectionNum() + "," 
    		+ "'" + s.getInstrutorID()+"'" + "," 
    		+ "'" + s.getDays() + "'" + "," 
    		+ "#" + s.getBeginTime().getTime().getMonth() + "/" + s.getBeginTime().getTime().getDate() + "/"  + s.getBeginTime().getTime().getYear()+  "#" + ","
    		+ "#" + s.getEndTime().getTime().getMonth() + "/" + s.getEndTime().getTime().getDate() + "/"  + s.getEndTime().getTime().getYear()+  "#" + ","
    		+ "#" + s.getStartDate().getTime().getMonth() + "/" + s.getStartDate().getTime().getDate() + "/"  + s.getStartDate().getTime().getYear()+  "#" + ","
    		+ "#" + s.getEndDate().getTime().getMonth() + "/" + s.getEndDate().getTime().getDate() + "/"  + s.getEndDate().getTime().getYear()+  "#" + ","
    		+ "'" + s.getRoomNum() + "'" + ")";
    My code compiles, but when I try to run it, I am getting an error when I try to run my TestSectionConnection class.

    Problems with query/update : [Microsoft][ODBC Microsoft Access Driver] Syntax error in date in query expression '#11/31/-1898#'.
    Press any key to continue...
    I dont get where it is getting the date 11/31/-1898. It seems like it is getting bad data in part of the date object. Would not setting pieces of the date object when I put it into the database cause this error?

    I have included my section da classes and my Access database in a zip file at the bottom of this post so you can look at it if you want to. I can post the code if you would rather read it here instead of getting it from the zip file. Any input is helpful. THanks
    Attached Files Attached Files
    Otaku no Kamisama – God of the Geeks

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Problem with a DA class

    Do a few System.out.println statements throughout your program and find out exactly WHERE this date is being set to an unreal year. I highly doubt putting it into the database will cause this error. I'm guessing you are doing some calculations and constructing the date elsewhere in your program, which is where the problem is probably occuring.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Problem with a DA class

    Quote Originally Posted by System_Error
    Do a few System.out.println statements throughout your program and find out exactly WHERE this date is being set to an unreal year. I highly doubt putting it into the database will cause this error. I'm guessing you are doing some calculations and constructing the date elsewhere in your program, which is where the problem is probably occuring.
    I agree with "System_Error".

    Another thing, if you are using an IDE it'd be a good idea to use breakpoints and trace the date value.
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Problem with a DA class

    It would be an even better idea to use prepared statements and forget about formatting the dates yourself.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width