java - CRUD -> 添加错误信息
问题描述
我想做一个 CRUD,但我的变量 SortieA 有问题,它是 NULL 吗?在此处查看图片 =>在此处输入图片描述
我的班级相册有问题吗?
public class Album {
private String codeA;
private String titreA;
private Date sortieA;
private Chanteur chanteurAlb;
public Album() {
}
public Album(String codeA, String titreA, Date sortieA, Chanteur chanteurAlb) {
this.codeA = codeA;
this.titreA = titreA;
this.sortieA = sortieA;
this.chanteurAlb = chanteurAlb;
}
public String getCodeA() {
return codeA;
}
public void setCodeA(String codeA) {
this.codeA = codeA;
}
public String getTitreA() {
return titreA;
}
public void setTitreA(String titreA) {
this.titreA = titreA;
}
public Date getSortieA() {
return sortieA;
}
public void setSortieA(Date sortieA) {
this.sortieA = sortieA;
}
public Chanteur getChanteurAlb() {
return chanteurAlb;
}
public void setChanteurAlb(Chanteur chanteurAlb) {
this.chanteurAlb = chanteurAlb;
}
这是我的要求
public boolean insertAlbum (Album alb)
{
boolean ok = ConnexionMySQL.getInstance().actionQuery("Insert into album (CodeA, TitreA, SortieA, IdentC) values ('" + alb.getCodeA() + "','" + alb.getTitreA() +
"'," + alb.getSortieA() + "," + alb.getChanteurAlb().getIdentC() + ")");
return ok;
}
请问你有什么想法吗?
解决方案
很明显,您在表单中输入的日期没有在您的 Album 对象中设置,因为您在 sql 语句中获得了 null。所以你需要弄清楚它在哪里丢失。
一旦解决了需要在 insertAlbum() 方法中将日期解析为格式正确的字符串的问题,因为在 sql 字符串中使用原始日期将不起作用。
推荐阅读
- ios - 将字符串值复制到另一个字符串?
- php - Codeigniter - 使用不同的 SMTP 设置发送电子邮件
- javascript - 如何以编程方式设置 HTMLElement 的宽度?
- azure - 文本拆分认知技能在 UI 中不可见
- php - 如何显示(分层)我的文章创建(PHP,Yii2)的年月?
- python - Pymongo 为某些键指定唯一约束
- java - 如何解决“参数不同”错误 - 单元测试
- c - 使用 gdb 调试时 setpgid(0, 0) 失败
- python - pandas - 从另一列中的每一列中替换/删除部分
- javascript - CSS 或 jQuery:如何获得可见的顶部