• 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

SQL Count() Invalid curser state

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay,
I'm getting an Invalid cursir stat Error when I try to execute the following code.
myStmt = "Select COUNT(Closure) " +
" FROM moded" +
" WHERE " +
"(closure = \'OPEN\' AND " +
"[logged on] > #"+dBegin+"# AND " +
"[logged on] < #" +dEnd + "# AND " +
"field38 = \'" +catCount[i][0] +"\');";
System.out.println(myStmt);
rs = stmt.executeQuery(myStmt);
rs.beforeFirst();
rs.next();
System.out.println(rs.getInt(1)); <------
Error occurs here, and I don't know why. Should the rs be 1 int?

Thank you in advance
John Martinson
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could it be that the command:


returned "false", which basically means that your query did not find any matches?
 
John Martinson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


yeilds "true" so rs.next(); is not failing.
 
John Martinson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem resolved. No Idea what it was I just changed retyped my SQL statement to make it clearer to read and it worked. No idear what made it work but here's the code for those really demented people who might want to figure it out.

 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Old where clause: WHERE closure = \'OPEN\'
New where clause: WHERE closure = 'OPEN'

the old query could not find a row that matched closure = \'OPEN\', so as stated earlier rs.beforFirst() method would "bomb" out because no rows were returned. When you changed to closure = 'OPEN' it found a row, and everything worked as planned. you should always check (if ( rs.next() ) if a row exists before calling any methods on the ResultSet.
[ June 21, 2005: Message edited by: Jamie Robertson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic