0

*例外 : *

       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();

尝试 {

            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, "记录更新成功"); 连接.close(); } 捕捉 (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); }

4

2 回答 2

0

在 where 子句之前有一个 , 。如果是日期,则 DOB 应包含在单引号内。你确定Mobile是一个整数吗?

"update Table1 set Name='" + Name + "' , Email='" + Email + "' , Mobile=" + Mobile + ", Address= '" + Address
+ "', DOB='" +Dob + "' where ID=" + Update;

但无论如何考虑使用 PreparedStatement 和参数传递。您使用的 SQL 容易受到 SQL 注入攻击。

于 2012-12-04T09:15:58.520 回答
0

请改用这个:

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>
于 2012-12-04T11:35:22.657 回答