Insertion error in Oracle database with Java

0

When I make a set of inserts in the bank, it says that only the course information has been entered, but the class

Console

STATUS DE CURSO: true 
STATUS DE CURSO: false

JOptionPane

TurmaDAO

publicclassTurmaDAOextendsDAO{publicTurmaDAO(){connection=Conexao.getConnection();}publicbooleaninserir(Turmaturma,Cursocurso){booleanstatus=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;
    }

Class

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) 
    
asked by anonymous 15.10.2017 / 20:23

1 answer

1

The error message described in JOptionPane says that a syntax error is occurring.

When looking at the syntax of the sql variable in the inserir() method, I noticed that a "T" is missing in the .nextval function of Oracle SQL%.

Correct the syntax by adding a "T" and it will work again.

    
15.10.2017 / 20:56