0
When I make a set of insertions in the bank, it says that only the information of the course were inserted, but gang nay.
Console
STATUS DE CURSO: true
STATUS DE CURSO: false
Joptionpane
Touradao
public class TurmaDAO extends DAO {
public TurmaDAO() {
connection = Conexao.getConnection();
}
public boolean inserir(Turma turma, Curso curso) {
boolean status = false;
sql = "INSERT INTO turmas VALUES (seq_id_turma.nexval, ?, ?, ?)";
try {
p = connection.prepareStatement(sql);
p.setString(1, turma.getNome());
p.setString(2, curso.getNome());
p.setString(3, curso.getPeriodo());
p.execute();
status = true;
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Não foi possível armazenar os dados da turma\n" + ex);
}
return status;
}
Gang
public class Turma {
private int id;
private String nome;
public Turma(String nome) {
this.nome = nome;
}
public int getId() {
return id;
}
public String getNome() {
return nome;
}
}
Testaturmadao
public class TestaTurmaDAO {
public static void main(String[] args) {
inserir();
}
public static void inserir() {
Curso cs = new Curso("Sistemas de Informação", "Tarde");
CursoDAO csDao = new CursoDAO();
boolean csStatus = csDao.inserir(cs);
System.out.println("STATUS DE CURSO: " + csStatus);
Turma tr = new Turma("2SIA");
TurmaDAO trDao = new TurmaDAO();
boolean trStatus = trDao.inserir(tr, cs);
System.out.println("STATUS DE TURMA: " + trStatus);
}
Bank structure
Nome Nulo? Tipo
------------- -------- -------------
ID_TURMA NOT NULL NUMBER(5)
NOME NOT NULL VARCHAR2(100)
NOME_CURSO NOT NULL VARCHAR2(100)
PERIODO_CURSO NOT NULL VARCHAR2(100)
Instead of returning a dialog box, return the complete stack of errors, so that the error and its origin can be seen better. And add that stack to the question.
– user28595
Forgive me for ignorance, but what would add to the stack of errors? Are those errors that appear when the application breaks?
– Guilherme Bigois
Comment the optionpane line and add
ex.printStackTrace();
. When you pop the error, add the question to the stack.– user28595
I added the error stack information.
– Guilherme Bigois
Where is line 19 of the Cursodao class?
– user28595
Oops! I found the error! The syntax of Insert is with
seq_id_turma.nexval
, missed the’T' to beseq_id_turma.nexTval
, but now you’re making another mistake.– Guilherme Bigois