【发布时间】:2015-06-19 20:58:11
【问题描述】:
我执行了一段代码,该代码用于显示 WampServer 上“update_action”列中的字段内容中的指定信息、表“事件”和数据库“base_rapport_tt”。在我的表格中,我添加了另一列,我将在其中存储显示的信息。我的目标是显示整个列的结果并将其存储在新的列顺序中。
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);
}
收件人字段第一列的结果很好。但问题是其他字段是前者的结果。
谢谢。
【问题讨论】:
-
一个小提示,考虑看看PreparedStatement。最好从 sql 注入中拯救自己
标签: java mysql jdbc phpmyadmin sql-update