java resultSet不可更新

时间:2014-03-24 11:27:11

标签: java database

我在结果集中遇到问题,当我对数据库内的值进行更新时,我的数据库中包含了主键 这是我的例外

com.mysql.jdbc.NotUpdatable: Result Set not updatable
  

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

1 个答案:

答案 0 :(得分:0)

我认为该表应该有一个主键,SQL查询应该选择它。 希望这可以帮到你。