如何通过NetBeans更新MS Access中的日期 [英] How to update date in ms access through netbeans

查看:121
本文介绍了如何通过NetBeans更新MS Access中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

* Exception:*

*Exception : *

       java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in       UPDATE statement

代码为:

    String Name = txtName.getText();`
    String Email = txtEmail.getText();
    String Mobile = txtMobile.getText();
    String Address = txtAddress.getText();
    String Dob = txtDob.getText();

尝试 {

try {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            connection = DriverManager.getConnection("jdbc:odbc:NewPData");
            String query = "update Table1 set Name='" + Name + "' , Email='" + Email + "' , Mobile=" + Mobile + ", Address= '" + Address

+',DOB =" + Dob +,其中ID =" +更新; PreparedStatement ps_Statement = connection.prepareStatement(query); ps_Statement.executeUpdate(); JOptionPane.showMessageDialog(panelID,记录更新成功"); connection.close(); } catch(ClassNotFoundException e){ e.printStackTrace(); } catch(SQLException e){ e.printStackTrace(); }

+ "', DOB=" +Dob + ", where ID=" + Update; PreparedStatement ps_Statement = connection.prepareStatement(query); ps_Statement.executeUpdate(); JOptionPane.showMessageDialog(panelID, "Record Updated Successfully"); connection.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }

推荐答案

请尝试以下操作:

String yourFormat = "dd-MMM-yy";
Date yourDateVariable = null;

SimpleDateFormat sdf = new SimpleDateFormat(yourFormat);

try {
    yourDateVariable = sdf.parse(Dob);
} catch ( Exception ex ) {
    // Do something
}

// Continue your code<code>

这篇关于如何通过NetBeans更新MS Access中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆