I am running into an error when I try to execute my sql code when I try to find a Section by the CourseNumber and the SectionNumber. It says I have a datatype mismatch in my SQL criteria.
Here is my SQL code that I am trying to use to get information from an access database.Problems with query/update : [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
Here is the method that I wrote.Code:String sql = "SELECT * FROM SECTIONS WHERE course_number= '" + s.getCourseNum()+"' AND section_number=" + s.getSectionNum();
I have been looking at this for about an hour and just cant see what I am doing wrong. My code is quitting when I try to execute my SQL Code which leads me to believe that I have a problem with my code. Any suggestions... If you need to see the full program or where I am calling the method that I wrote, post and I will zip it or post it and let you see it.Code:public Section findSectionByCourNumSectNum(Section s) throws SectionException { String sql = "SELECT * FROM SECTIONS WHERE course_number= '" + s.getCourseNum()+"' AND section_number=" + s.getSectionNum(); System.out.println(sql); Section foundSection = new Section(); try { System.out.println("Before creating statement object."); Statement stmt = conn.createStatement(); System.out.println("Before creating ResultSet using the stmt to execute the SQL code."); ResultSet rs = stmt.executeQuery(sql); System.out.println("After creating ResultSet using the stmt to execute the SQL code."); if(rs.next()) { foundSection.setDatabaseID(rs.getInt(1)); System.out.println("Found Section DatabaseID: "+ foundSection.getDatabaseID() ); foundSection.setCourseNum(rs.getString(2)); System.out.println("Found Section CourseNum: " + foundSection.getCourseNum()); foundSection.setSectionNum(rs.getInt(3)); System.out.println("Found Section SectionNum: " + foundSection.getSectionNum()); foundSection.setInstructorID(rs.getString(4)); System.out.println("Found Section InstructorID: " + foundSection.getInstrutorID() ); foundSection.setDays(rs.getString(5)); System.out.println("Found Section Days: " + foundSection.getDays()); foundSection.setBeginTime(rs.getInt(6)); System.out.println("Found Section BeginTime: " + foundSection.getBeginTime() ); foundSection.setEndTime(rs.getInt(7)); System.out.println("Found Section EndTime: " + foundSection.getEndTime() ); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(rs.getLong(8)); foundSection.setStartDate(cal); System.out.println("Found Section StartDate: " + foundSection.getStartDate().getTime()); cal.clear(); cal.setTimeInMillis(rs.getLong(9)); foundSection.setEndDate(cal); System.out.println("Found Section EndDate: " + foundSection.getEndDate().getTime()); foundSection.setRoomNum(rs.getString(10)); System.out.println("Found Section Room Number: " + foundSection.getRoomNum()); return foundSection; } else { return null; } }//end try catch(SQLException sqe) { throw new SectionException(sqe.getMessage()); }//end catch }




Reply With Quote