首页 > 解决方案 > 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;
    }

请问你有什么想法吗?

在此处输入图像描述

标签: javamysqlsqlswingjdbc

解决方案


很明显,您在表单中输入的日期没有在您的 Album 对象中设置,因为您在 sql 语句中获得了 null。所以你需要弄清楚它在哪里丢失。
一旦解决了需要在 insertAlbum() 方法中将日期解析为格式正确的字符串的问题,因为在 sql 字符串中使用原始日期将不起作用。


推荐阅读