This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes entry removal from DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "entry removal from DB" Watch "entry removal from DB" New topic

entry removal from DB

egbai mmumene
Ranch Hand

Joined: Sep 18, 2012
Posts: 46
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(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.ResultSetImpl.checkRowPos(
at com.mysql.jdbc.UpdatableResultSet.checkRowPos(
at com.mysql.jdbc.ResultSetImpl.getInt(
at com.mysql.jdbc.ResultSetImpl.getInt(
at mm.main.moviemethod.actionPerformed(
at javax.swing.AbstractButton.fireActionPerformed(
then here is my code
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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:

I agree. Here's the link:
subject: entry removal from DB
It's not a secret anymore!