【问题标题】:Insert date from a JDateChooser to a MySql database将日期从 JDateChooser 插入 MySql 数据库
【发布时间】:2018-07-31 09:50:17
【问题描述】:

你好我不知道如何将日期从 JDateChooser 插入 mysql 转换为接受 mysql 的格式...... 我正在使用 MVC fremework ...并且我正在以下列方式插入数据 ....

是我的驱动类

添加一个 jtxfile 只是为了尝试使用我的应用程序调用它

txtFecha2 (this.vistaAlumno.getTxtFecha2().getText())

在视图中,我为每个组件设置了 GET 和 SET 方法,以便我可以从另一个类中使用它们...

JDateChooser 称为 jdFecha。

public void actionPerformed(ActionEvent e) {

        if (e.getSource() == vistaAlumno.getBtnInsertar()) {

            //obtiene ID de producto  this.mimodelo.getDatosVentaxFechas( this.frmconsulta.__fecha1.getDate(), this.frmconsulta.__fecha2.getDate() ) );
            //String cat[] = this.vistaAlumno.__lista_categorias.getSelectedItem().toString().split("-");
            if (this.modeloAlumno.NuevoProducto(
                    this.vistaAlumno.getTxtMatricula().getText(),
                    this.vistaAlumno.getTxtNombre().getText(),
                    this.vistaAlumno.getTxtApellido_p().getText(),
                    this.vistaAlumno.getTxtApellido_m().getText(),
                    this.vistaAlumno.getTxtSexo().getText(),
                    this.vistaAlumno.getTxtFecha2().getText(),
                    this.vistaAlumno.getTxtDireccion().getText(),
                    this.vistaAlumno.getTxtCorreo().getText()// ,
            // cat[0].trim()
            )) {
                this.vistaAlumno.getJtDatosAlumno().setModel(this.modeloAlumno.getTablaAlumno()); //actualiza JTable
                JOptionPane.showMessageDialog(null, "Nuevo Alumno Registrado");
            } else {
                JOptionPane.showMessageDialog(null, "Error: Verifique los datos del nuevo Alumno");
            }

您好,非常感谢

【问题讨论】:

    标签: java c# mysql sql jdatechooser


    【解决方案1】:

    我不是在看你的代码,但至于从 JDateChooser 添加日期你可以使用这个代码

    String datee=((JTextField)a.getDateEditor().getUiComponent()).getText();
    

    然后就可以添加进去了

    ps.setString(0,a);
    

    在上面的代码中,

    a 是 JDateChooser

    ps 是 PreparedStatement

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2013-04-27
      • 1970-01-01
      相关资源
      最近更新 更多