java结果集不可更新

java结果集不可更新,java,database,Java,Database,当我对数据库中的值进行更新并且在数据库中有primarykey时,resultset中出现了一个问题 这是我的一个例外 com.mysql.jdbc.NotUpdatable: Result Set not updatable 受保护的void processPairWords() { int count1=0; try { Statement st1; Statement st2; st1 = con

当我对数据库中的值进行更新并且在数据库中有primarykey时,resultset中出现了一个问题 这是我的一个例外

com.mysql.jdbc.NotUpdatable: Result Set not updatable
受保护的void processPairWords() {

       int count1=0;
      try {
          Statement st1; 
          Statement st2; 

          st1 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                     ResultSet.CONCUR_UPDATABLE);
           st2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                     ResultSet.CONCUR_UPDATABLE);
          ResultSet res1 = st1
         .executeQuery("SELECT txt,freq,prob FROM searchtb WHERE txttype=1");

          ResultSet res2= st2
         .executeQuery("SELECT txt,freq,prob FROM searchtb WHERE txttype=2");
          res1.beforeFirst();
          res2.beforeFirst();

          while (res1.next()){  
              while(res2.next())
              {
               if(res2.getString("txt").startsWith(res1.getString("txt")))
                  {
                      int prob2=res2.getInt("freq");
                      int prob1=res1.getInt("freq");
                      double prob=prob2/prob1; 
                       res2.updateDouble("prob", prob); 
                          res2.updateRow();       
                          count1++;
                          System.out.println(res2.getString("txt"));

                  }                   }
               System.out.println("loop1");
          }

       conn.commit(); 
          System.out.println("pairs count"+count1 );
      } catch (SQLException e) {
          e.printStackTrace();
      } 
  }

我认为表应该有一个主键,SQL查询应该选择它。
希望这能对您有所帮助。

也许这个链接可以帮助您:用于searchtb的ddl?而且,我可能错了,但是您不需要将主键作为查询的一部分返回,以便它可以更新吗?