gpt4 book ai didi

java - 将日期从 JDateChooser 插入到 MySql 数据库

转载 作者:行者123 更新时间:2023-11-29 17:16:07 26 4
gpt4 key购买 nike

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

是我的驱动程序级别

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

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

在 View 中,我为每个组件设置了 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");
}

问候和非常感谢

最佳答案

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

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

然后你可以将其添加到

ps.setString(0,a);

在上面的代码中,

a is JDateChooser

ps is PreparedStatement

希望对你有帮助

关于java - 将日期从 JDateChooser 插入到 MySql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com