不允许参数标记(更新Access数据库)

时间:2016-09-10 16:42:38

标签: java ms-access jdbc ucanaccess

jQuery.toggle

我正在尝试更新Access数据库中的记录,并且它不断地向我抛出异常,例如不允许使用参数标记。

有人可以帮我这个吗?

2 个答案:

答案 0 :(得分:2)

String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";

ResultSet rs = st.executeQuery(sql);

没有意义,因为

  1. 该查询不返回ResultSet和
  2. executeQuery无法知道哪些值与参数占位符(?)对应。
  3. 如果省略该行,则“参数标记不允许”错误将消失,您可以使用PreparedStatement继续更新。

答案 1 :(得分:0)

try{
         Statement st = connect.createStatement();
         String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
         try {
        ps = connect.prepareStatement(sql);

        ps.setInt(1, roll_mo);
        ps.setString(2, name_mo);
        ps.setString(3, Fname_mo);
        ps.setString(4, fcnic_mo);
        ps.setString(5, dob_mo);
        ps.setInt   (6, Class_mo);
        ps.setString(7, add_mo);
        ps.setString(8, city_mo);
        ps.setString(9, prvnce_mo);
        ps.executeUpdate();
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, "Record Modified !");
        search_input.requestFocus();
         }

         catch(Exception ex)
         {
               ex.printStackTrace();
         }

    }

         catch(Exception e)
    {
        Toolkit.getDefaultToolkit().beep();
        JOptionPane.showMessageDialog(null, e);
    }