I have been receiving an error that is the following:
Exception in thread "main" java.util.InputMismatchException
I've started researching on the internet and everyone agreed that after a scanner you have to put a scanner.next(); . The thing is that it works until I want to create a third row which gives me the same problem again.
This is the code snippet, which belongs to a switch:
case 1: //CREAR NUEVO SUPERGUERRERO
System.out.print("Nombre de superguerrero: ");
guerrero = scan.next();
System.out.print("Descripcion de superguerrero: ");
descripcion = scan.next();
scan.next(); //Es aquí donde ví que había que poner el scanner
System.out.print("Poder de fuego: ");
fuego = scan.nextInt(); //Y es aquí cuando me da el error mencionado
System.out.print("Poder de agua: ");
agua = scan.nextInt();
System.out.print("Poder de viento: ");
viento = scan.nextInt();
if (fuego > 5 || fuego < 1 || agua > 5 || agua < 1 || viento > 5 || viento < 1) {
System.out.println("Los poderes deben ser del 1 al 5");
break;
} else {
stmt.executeUpdate("INSERT INTO superespecie VALUES(null, '"+guerrero+"', '"+descripcion+"', '"+fuego+"', '"+agua+"', '"+viento+"')");
break;
}
Thank you very much for your help :)
Ok, I have found my problem. This is not a scanner.next();
Must be a scanner.nextLine();