I'm doing a Java program that has to interact with a MySQL database, and I'm trying to delete a row of a table from a query in Java.
The problem is that when I try to convert a String in Java, "2021/2022" to char(9) I get an error that says that data is too long for column. Can anyone help?
This is the method that should delete the row:
public boolean borrarMatricula(Connection conn, int alumno, int profesor, int asignatura,
String c){
boolean borrado = false;
String drop = "DROP PROCEDURE IF EXISTS DELETE_ENROLLMENT";
String rutina = "CREATE PROCEDURE DELETE_ENROLLMENT(IN alumno double(4,0), "
+ "IN profesor double(2,0), IN asignatura double(3,0), IN c char(9))"
+ "BEGIN "
+ "DELETE FROM MATRICULAS WHERE codigoAlumno=alumno and "
+ "codigoProfesor=profesor and codigoAsignatura=asignatura and curso=c;"
+ "END";
try{
Statement s = conn.createStatement();
s.execute(drop);
s.execute(rutina);
CallableStatement cs=conn.prepareCall("{call DELETE_ENROLLMENT(" +
alumno + "," + profesor + "," + asignatura + "," + c + ")}");
cs.execute();
borrado = true;
}
catch(SQLException e){
Vista.muestraErrorSQL(e);
}
catch(Exception e){
e.printStackTrace(System.err);
}
return(borrado);
}
"Curso" is defined as a char(9), and the String I'm using is 2021/2022