• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invalid Cursor state- Please help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Luke,
generally when you want to determine whether a row exists or not in a table, you do something similar to:

What is happening in your code is that a certain selection of your where clause is returning zero results (ie. no record was found in the database, the result-set is empty), so it is invalid to request a column out of the result set, hence the invalid cursor state error.
James.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers I've got it working.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic