• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

entry removal from DB

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trying to delete an entry from my database based on a button click but i am getting an error. here's my code and the error message
java.sql.SQLException: Illegal operation on empty result set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:835)
at com.mysql.jdbc.UpdatableResultSet.checkRowPos(UpdatableResultSet.java:226)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2636)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2777)
at mm.main.moviemethod.actionPerformed(moviemethod.java:212)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018).
then here is my code
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At line 10 your query returns a ResultSet. It has no rows in it.

At line 11 you call next() on that ResultSet; it returns false, meaning there are no more rows to read, but you ignore that.

Then at line 13 you try to read something from the current row, but there is no current row, so you get an exception.

So, the first problem is that your query returns zero rows. It's possible that is something you should be expecting, and if so then you should write your code appropriately. If not, then the way you build your query is wrong. At any rate I would strongly recommend you learn how to use PreparedStatement, instead of building your query by concatenating strings. Much less subject to errors and also much less subject to SQL injection attacks which could damage your database.

One other thing: if you want to add one to a column in a table (which is what your code looks like), you have chosen a very roundabout way of doing that. Here's a much easier way to do that:



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!