I have the following class and when I run it I get an error which is:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "com.mysql.jdbc.JDBC4ResultSet@42147df5"
The error occurs on this line:
fono = Integer.valueOf(fonoS);
This is the Code:
public Counter(){
String query = "SELECT MAX(FONO) from forders";
try {
connectOrders.pst = connectOrders.con.prepareStatement(query);
connectOrders.rs = connectOrders.pst.executeQuery(query);
if (connectOrders.rs.next()){
Object fonoO = connectOrders.rs;
String fonoS= fonoO.toString();
fono = Integer.valueOf(fonoS);
try {
serialisationFoNo(fono);
} catch (IOException ex) {
Logger.getLogger(Counter.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (connectOrders.rs.wasNull()){
fono = 1;
try {
serialisationFoNo(fono);
} catch (IOException ex) {
Logger.getLogger(Counter.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (SQLException ex) {
Logger.getLogger(Counter.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, ex);
}
}
Why is it throwing this exception I have used the same syntax of code elsewhere in the application and it works.
NOTE: I have also tried using Integer.parseInt(); but even that throws a similar exception.
com.mysql.jdbc.JDBC4ResultSet@42147df5) and that is obviously not a valid integer that you could parse.