Skip to content

Commit

Permalink
adicionando primeiro comando de update dos dados no banco
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Borges committed Jun 20, 2022
1 parent 537d28f commit 46cca2d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
Binary file modified out/production/trabalho-final-psc/SistemaCursos.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion src/SistemaCursos.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import UtilsPersistencia.conectorBanco;
import utilsPersistencia.conectorBanco;
import entidades.*;
import excecoes.AlunoException;
import interfaces.Validador;
Expand Down Expand Up @@ -399,6 +399,9 @@ private void alocarSala(){
else {
if(!curso.cadastrarSala(sala))
System.out.println("Sala ja alocada!");
else{
conector.alocarSalaAoCurso((int)curso.getCodigo(), sala.getNome());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package UtilsPersistencia;
package utilsPersistencia;

import entidades.*;
import java.sql.Connection;
Expand Down Expand Up @@ -86,6 +86,19 @@ public void inserirCurso(Curso curso){
}
}

public void alocarSalaAoCurso(int idCurso, String nomeSala){
PreparedStatement statement;

try{
statement = connection.prepareStatement("UPDATE Curso SET nome_sala = ? WHERE codigo = ?");
statement.setString(1, nomeSala);
statement.setInt(2, idCurso);
statement.executeUpdate();
}catch (SQLException exception){
System.out.println("Um erro ocorreu ao atualizar o dado no banco de dados.");
}
}

@Override
public void close() throws Exception {
if(connection != null && !connection.isClosed())
Expand Down

0 comments on commit 46cca2d

Please sign in to comment.