Java 将eclipse连接到ODBC驱动程序时出现计数字段错误

Java 将eclipse连接到ODBC驱动程序时出现计数字段错误,java,eclipse,swing,ms-access,Java,Eclipse,Swing,Ms Access,我在尝试使用MicrosoftAccess和eclipse在数据库中创建记录时出错 [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect 显示的连接已关闭。这是我连接到ODBC驱动程序的代码 public class DBController { private Connection con; public void setUp(String dsn) { try { Class.

我在尝试使用MicrosoftAccess和eclipse在数据库中创建记录时出错

    [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
显示的连接已关闭。这是我连接到ODBC驱动程序的代码

    public class DBController {
private Connection con;

public void setUp(String dsn) {
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");          
    } catch (Exception e) {
        System.out.println("Load driver error");
    }
    try {

        String s = "jdbc:odbc:" + dsn;
        con = DriverManager.getConnection(s, "", "");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public ResultSet readRequest(String dbQuery) {
    ResultSet rs = null;
    try {
        Statement stmt = con.createStatement();
        rs = stmt.executeQuery(dbQuery);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rs;
}

public int updateRequest(String dbQuery) {
    int count = 0;
    try {
        Statement stmt = con.createStatement();
        count = stmt.executeUpdate(dbQuery);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return count;
}

public void terminate() {
    try {
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

这是我给createUser的代码

        public boolean createUser() {
    boolean success = false;
    DBController db = new DBController();
    db.setUp("IT Innovation Project");
    String sql = "INSERT INTO forumUsers(users_userName,users_password,users_NRIC,users_securityQuestion,users_answer) ";
    sql += "VALUES ('" + userName + "','" + pwd + "','" + nric + "','"
            + securityQuestion + "','" + answer + "')";
    System.out.println(sql);
    if (db.updateRequest(sql) == 1)
        success = true;
    db.terminate();
    return success;
}
我已经按照数据库表列重新排列了序列,但它仍然显示count字段错误。那我该怎么修呢?任何帮助都将不胜感激。 这是我的秋千

    public void submitSignup(ActionEvent e) {
    String userName = jTextField_userName.getText();
    String pwd = new String(jPasswordField.getPassword());
    String nric = jTextField_nric.getText();
    String securityQuestion = jComboBox_securityQuestion.getSelectedItem()
            .toString();
    String answer = jTextField_answer.getText();

    if (userName.equals("") || pwd.equals("") || nric.equals("")
            || securityQuestion.equals("") || answer.equals(""))
        JOptionPane.showMessageDialog(null, "Please enter all text field");
    else {
        eForumUser user = new eForumUser(userName, pwd, nric,
                securityQuestion, answer);
        if (user.isExist())
            JOptionPane.showMessageDialog(null,
                    "User already exists! Cannot create.");
        else {
            if (user.createUser() == true)
                ;
            JOptionPane.showMessageDialog(null,
                    "User record created successfull!");
        }
    }
}
我认为应该是:

  String sql = "INSERT INTO forumUsers(users_userName,users_password,users_NRIC,users_securityQuestion,users_answer) " +
         "VALUES (?,?,?,?,?)";
            System.out.println(sql);
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1,users_userName);
            ps.setString(2,users_password);
            ps.setString(3,users_NRIC);
            ps.setString(4,users_securityQuestion);
            ps.setString(5,users_answer);
            int checks = ps.executeUpdate();
            if(checks != 0){                
                  success = true;                       
            }
            else{
              System.out.println("Failed to insert user data");
            }
 db.terminate();

我已经编辑过了。是我的序列出错了吗?“是我的序列出错了吗?”如果“序列”是指添加标记、发布问题、然后添加符合标记的代码的顺序,那么是的。一次完成这一切。否则我不知道那句话是什么意思。嗯,我的意思是我应该根据数据库列的顺序使用Insert语句吗?我不知道。我知道Swing,不是D/B。有人能给我解释一下“计数字段不正确”是什么意思吗?