【问题标题】:CRUD -> Add error messageCRUD -> 添加错误信息
【发布时间】:2018-11-05 02:37:57
【问题描述】:

我想做一个 CRUD,但我的变量 SortieA 有问题,它是 NULL 吗?看这里的图片 => enter image description here

这是我班级相册的问题?

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;
    }

请问你有什么想法吗?

enter image description here

【问题讨论】:

  • 您如何判断您发布的代码是否足以让我们判断是什么导致问题?在我看来,我认为您没有,从我们的角度来看,minimal reproducible example 将有很大帮助。请考虑创建一个并将其与您的问题一起发布。
  • 除了@HovercraftFullOfEels 建议的 MCVE 注意:not 发布(链接到)textual 信息的图像 - 发布文本本身(作为文本)。尤其是当该消息的关键不是英语时。 (谷歌还没有翻译图片中的文字!)

标签: java mysql sql swing jdbc


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多