Arreglo para guardar nuevas materias
This commit is contained in:
@@ -122,13 +122,13 @@ public class ControladorCurso {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int guardarCurso(Curso curso) {
|
public static int guardarCurso(Curso curso) {
|
||||||
|
if (curso.getId() == -1) {
|
||||||
|
curso.setId(ControladorCurso.getUltimoCurso().getId() + 1);
|
||||||
|
return nuevoCurso(curso);
|
||||||
|
}
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("UPDATE curso SET descripcion = ? WHERE id = ?");
|
PreparedStatement pst = conn.prepareStatement("UPDATE curso SET descripcion = ? WHERE id = ?");
|
||||||
if (curso.getId() == -1) {
|
|
||||||
curso.setId(ControladorCurso.getUltimoCurso().getId() + 1);
|
|
||||||
return nuevoCurso(curso);
|
|
||||||
}
|
|
||||||
pst.setString(1, curso.getDescripcion());
|
pst.setString(1, curso.getDescripcion());
|
||||||
pst.setInt(2, curso.getId());
|
pst.setInt(2, curso.getId());
|
||||||
return pst.executeUpdate();
|
return pst.executeUpdate();
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ public class ControladorMateria {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int guardarMateria(Materia materia) {
|
public static int guardarMateria(Materia materia) {
|
||||||
|
if (materia.getId() == -1) {
|
||||||
|
materia.setId(ControladorMateria.getUltimaMateria().getId() + 1);
|
||||||
|
return nuevaMateria(materia);
|
||||||
|
}
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
try {
|
try {
|
||||||
PreparedStatement pst = conn.prepareStatement("UPDATE materia SET nombre = ?, acronimo = ?, curso_id = ? WHERE id = ?");
|
PreparedStatement pst = conn.prepareStatement("UPDATE materia SET nombre = ?, acronimo = ?, curso_id = ? WHERE id = ?");
|
||||||
@@ -105,6 +109,20 @@ public class ControladorMateria {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int nuevaMateria(Materia materia) {
|
||||||
|
Connection conn = GestorConexiones.getConexion();
|
||||||
|
try {
|
||||||
|
PreparedStatement pst = conn.prepareStatement("INSERT INTO materia (id,nombre,acronimo,curso_id) VALUES (?,?,?,?)");
|
||||||
|
pst.setInt(1, materia.getId());
|
||||||
|
pst.setString(2, materia.getNombre());
|
||||||
|
pst.setString(3, materia.getAcronimo());
|
||||||
|
pst.setInt(4, materia.getCurso_id());
|
||||||
|
return pst.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Materia getMateria(int id) {
|
public static Materia getMateria(int id) {
|
||||||
Connection conn = GestorConexiones.getConexion();
|
Connection conn = GestorConexiones.getConexion();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user