Я выполнил код, который используется для отображения указанной информации из содержимого поля в столбце «update_action» таблицы «инцидент» базы данных «base_rapport_tt» на 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);
}
результат первого столбца поле получателя хорошо. Но проблема в том, что другие поля являются результатом первого.
спасибо.
Маленький tipp, рассмотрим возможность [PreparedStatement] (http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html). Лучше сэкономить себя от внедрения sql – SomeJavaGuy