java - 数据截断: incorrect data value : 'yyyy MMM d' for column 'date_acd' at row 1

标签 java mysql

您好,我的程序中出现此错误,但我找不到解决方案。这是我的代码,请跟随我:

private void bt2ActionPerformed(java.awt.event.ActionEvent evt) {                                    
try{

        if (JOptionPane.showConfirmDialog(null,"confirmer la modification ","modification sur un departement",
            JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
        st.execute("Update departement set code_departement = '"+txtcode.getText()+"',nom_departement = '"+txtnom.getText()
                +"',date_acd = '"+jdat.getDateFormatString()+"' where code_departement = "+txtcode.getText());
        AfficherDepartement();
        }

    }   catch(Exception e)  {JOptionPane.showMessageDialog(null,"erreur de modifier le departement !!!!\n"+e.getMessage());
            System.err.println(e);}

最佳答案

在设置为查询之前,将日期格式化为'yyyy-MM-dd'。 您可以使用它

java.text.SimpleDateFormat

类。

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(new Date());

关于java - 数据截断: incorrect data value : 'yyyy MMM d' for column 'date_acd' at row 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37850554/

相关文章:

java - 如何正确使用NIO选择器?

MySQL,两列共享相同的连接

mysql - 如何限制 SQLite/MySQL 中的列值

java - 是否有系统范围的 Preferences API 版本?

java - String 中的 4 个子字符串

php - 使用 select 获取变量

php - SQL 提交 0 而不是实际值。还删除@和.在电子邮件地址中

php - 使用 imap php 函数获取未读消息的计数

java - 将PayPal功能集成到Java中

java - 在 Android 应用程序中将两部手机/用户链接在一起