-1
Statement st = connect.createStatement();
String sql = "update StudentDatabaseS set RollNo = ?, FullName = ?, FatherName = ?, FatherCNIC = ?, DateOfBirth = ?, Class = ?, Address = ?, City = ?, Province = ? where RollNo = '"+Srollno+"'";
ResultSet rs = st.executeQuery(sql);

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

I am trying to update a record in an Access database and it is continuously throwing me exceptions, for example parameter markers not allowed.

Can someone help me with this?

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
Abdul Wahab
  • 89
  • 1
  • 9

2 Answers2

2

When

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

the line

ResultSet rs = st.executeQuery(sql);

makes no sense because

  1. that query does not return a ResultSet, and
  2. executeQuery has no way of knowing what values correspond to the parameter placeholders (?).

If you omit that line then the "parameter marker not allowed" error will go away and you can carry on with your UPDATE using the PreparedStatement.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
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);
    }      
Abdul Wahab
  • 89
  • 1
  • 9