【发布时间】:2013-11-16 22:09:21
【问题描述】:
我正在尝试在数据库中插入一些数据,但遇到了一些麻烦。目前我无法将数据添加到我的表中,我不知道为什么。
我使用了一些你不需要理解的通用方法,这适用于我的所有项目,并且在任何项目中都没有任何错误。
以下是我在 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;
}
从我的控制器调用方法“adicionarTurno”:
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());
}
}
这是我的 Escola 实体:
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;
}
}
当我尝试在 arrayList 中插入一些值并尝试将它们插入数据库中时(使用 EscolaController),我收到以下错误消息(第一行是我尝试插入的“toString”):
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
我做错了什么?
【问题讨论】: