A simple problem, which is to hard for me to solve. Im trying to get my program to make sure that duplicate records arent added to a database. I've created a select query (see below) which brings in the values from the selected options, when the add record button is clicked. Where roomNumberValue, courseCodeValue etc are index values of combo boxes.
String queryAddRecord = "SELECT * FROM Lessons WHERE " +
"RoomNumber ='" + roomNumberValue + "' AND " +
"CourseID ='" + courseCodeValue + "' AND " +
"StaffID ='" + staffMemberValue + "' AND " +
"LessonTimeStart ='" + lessonStartTimeValue + "' AND " +
"LessonTimeEnd ='" + lessonEndTimeValue + "' AND " +
"LessonNameID = '" + lessonNamesValue + "' AND " +
"LessonDay = '" + lessonDayValue + "' AND " +
"LessonDateStart ='" + txtLessonStartDate.getText() + "' AND " +
"LessonDateEnd ='" + txtLessonEndDate.getText() + "'";
ResultSet rs = statementAddRecord.executeQuery( queryAddRecord );
display( rs );
statementAddRecord.close();
When I try to add the record into the DB brings up a SQL cursor error "Invalid cursor state" on the * line
public void display (ResultSet rs)
{
try
{
rs.next();
int recordNumber = rs.getInt(1); *INVALID CURSOR STATE HERE
if(recordNumber !=0)
{
txtaOutput.append("\nInvalid entry, Record already exists");
}
else //Add record no duplicates values
{
//Add record
}
Please help me.