Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将处理结果存储在表中_Java_Mysql_Jdbc_Phpmyadmin_Sql Update - Fatal编程技术网

Java 将处理结果存储在表中

Java 将处理结果存储在表中,java,mysql,jdbc,phpmyadmin,sql-update,Java,Mysql,Jdbc,Phpmyadmin,Sql Update,我执行了一个代码,该代码用于显示WampServer上“更新操作”列、表、事件、数据库、基本关系”字段内容中的指定信息。在我的表中,我添加了另一列,我将在其中存储显示的信息。我的目标是显示整个列的结果,并将其存储在新的列顺序中 try { String Sql="Select Update_Action from incident where id_incident ='"+jTextField3.getText()+"' and Status like

我执行了一个代码,该代码用于显示WampServer上“更新操作”列、表、事件、数据库、基本关系”字段内容中的指定信息。在我的表中,我添加了另一列,我将在其中存储显示的信息。我的目标是显示整个列的结果,并将其存储在新的列顺序中

try
    {   
        String Sql="Select Update_Action from   incident    where id_incident ='"+jTextField3.getText()+"' and Status like 'Closed'";
        con = getConnection("jdbc:mysql://localhost:3306/base_rapport_tt","root","");
        stmt=con.createStatement();
        rs=stmt.executeQuery(Sql);

        while(rs.next()) {
            str=rs.getString("update_Action");

            while(!"".equals(str)){
              int debut=str.indexOf('(')+1;
              int fin=str.indexOf(')',debut);
              nom += " "+str.substring(debut,fin);
              str=str.substring(fin+1,str.length()); 
              nom+=", "; 
            } 
         }
    } 
    catch (Exception e) {
       JOptionPane.showMessageDialog(this,e);
   }
我尝试使用以下代码:

try
{ 
   String Sql="Select Update_Action,id_incident from   incident
where Status like 'Closed'";
  con = getConnection("jdbc:mysql://localhost:3306/base_rapport_tt","root","");
 stmt=con.createStatement();
 rs=stmt.executeQuery(Sql);

 while(rs.next()) {
     str=rs.getString("update_Action");
     nom="";
     while(!"".equals(str)){
        int debut=str.indexOf('(')+1;
        int fin=str.indexOf(')',debut);
        nom += " "+str.substring(debut,fin);
        str=str.substring(fin+1,str.length()); 
        nom+=", ";  

        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/base_rapport_tt", "root", "");
        String query = "update incident set intervenants = ? where id_incident like '%'";
        java.sql.PreparedStatement preparedStmt = conn.prepareStatement(query);
        preparedStmt.setString(1,nom);
        preparedStmt.executeUpdate();
        conn.close();    
      }
   }
}
catch (Exception e) 
{
           //JOptionPane.showMessageDialog(this,e);
}
收件人字段第一列的结果良好。但问题是其他领域是前者的结果

谢谢。

问题在这里

 String query = "update incident set intervenants = ? where id_incident like '%'";
此查询更新所有行(id\u事件,如“%”)!您需要使用筛选器主键(我认为它是id\u事件)

您必须执行此查询

String query = "update incident set intervenants = ? where id_incident = ? ;
preparedStmt.setString(1,nom);
preparedStmt.setInt(2,rs.getInt("id_incident")); 
附言。 1) 使用单一更新是不好的。例如,最好的方法是使用批量更新

2) 为什么选择和更新时使用不同的连接?都一样