Reputation: 4572
I'm trying to insert some data in a DB but I'm having some troubles. Currently I can't add data to my table and I don't know why.
I'm using some generic methods that you don't need to understand, this works in all my projects and don't have any error in any of this projects.
Following is my method in the EscolaDAO:
public boolean adicionarTurno(String turno) {
String sql = "INSERT IGNORE INTO Turno (descricao) values ?;";
ArrayList<Object> params = new ArrayList<Object>();
params.add(turno);
operacaoEscrita(sql, params);
return true;
}
The method "adicionarTurno" is called from my Controller:
EscolaDAO modelo = new EscolaDAO();
public void adicionarHorario(Escola escola){
for(Turno temp : escola.getTurnos()){
System.out.println("Controle Turno: " + temp.getNome());
modelo.adicionarTurno(temp.getNome());
}
}
And here's my Escola entity:
public class Escola {
private String nomeEscola;
private ArrayList<Turno> turnos = new ArrayList<Turno>();
private ArrayList<Dia> dias = new ArrayList<Dia>();
public Escola() { }
public Escola(String nomeEscola) {
this.nomeEscola = nomeEscola;
}
public ArrayList<Dia> getDias() {
return dias;
}
public void setDias(ArrayList<Dia> dias) {
this.dias = dias;
}
public String getNomeEscola() {
return nomeEscola;
}
public void setNomeEscola(String nomeEscola) {
this.nomeEscola = nomeEscola;
}
public ArrayList<Turno> getTurnos() {
return turnos;
}
public void setTurnos(ArrayList<Turno> turnos) {
this.turnos = turnos;
}
}
Controle Turno: Vespertino
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Vespertino'' at line 1
Controle Dia: Segunda-feira
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Segunda-feira'' at line 1
Controle Dia: Terça-feira
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Terça-feira'' at line 1
Controle Dia: Quarta-feira
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Quarta-feira'' at line 1
Controle Dia: Quinta-feira
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Quinta-feira'' at line 1
Upvotes: 0
Views: 386
Reputation: 691735
The correct syntax is:
insert ignore into Turno values (?)
Note that:
You'd better specify the column names, to make your code clearer and safer:
insert ignore into Turno (name_of_the_column) values (?)
Reading the documentation saves hours:
http://dev.mysql.com/doc/refman/5.7/en/insert.html
Upvotes: 1