public int UserUpdateDetail(String id, String table) throws Exception {//更新newsdetail表的数值
Connection conn = null;
int rCount=0;
try {
//获取连接
Class.forName(driver);
conn = DriverManager.getConnection(url, databseUser, password);
//获取结果
String sql1 = "select * from " + table + " where newsid= " + id;
Statement stat1 = conn.createStatement();
ResultSet rs1 = stat1.executeQuery(sql1);
int tmp = 0;
int sense2 = 0;
int mood_neg2 = 0;
int mood_neu2 = 0;
int mood_pos2 = 0;
int mood = 0;
int hot = 0;
int index = 0;
while (rs1.next()) {
mood = rs1.getInt(4);
hot = rs1.getInt(5);
sense2 = rs1.getInt(6);
index = rs1.getInt(8);
mood_neg2 = rs1.getInt(9);
mood_pos2 = rs1.getInt(11);
mood_neu2 = rs1.getInt(13);
break;
}
System.out.println("before:"+sense2);
while(true) {
tmp = (int)(Math.random() * 100);
if(tmp < sense2 && tmp >= sense2/2) {
sense2 = tmp;
break;
}
}
while(true) {
tmp = (int)(Math.random() * 100);
if(tmp < mood_neg2 && tmp >= mood_neg2/2) {
mood_neg2 = tmp;
break;
}
}
while(true) {
mood_neu2 = (int)(Math.random() * 50);
if((mood_neu2 + mood_neg2) < 80) {
break;
}
}
mood_pos2 = 100 - mood_neg2 - mood_neu2;
//填充SQL
String sql2 = " update " + table + " set hot = " + hot + "," + " sense2 = " + sense2 + "," + " mood_neg2 = " + mood_neg2 + "," + " mood_neu2 = " + mood_neu2 + "," + " mood_pos2 = " + mood_pos2 + " where newsid = " + id;
rCount = stat1.executeUpdate(sql2);
System.out.println(rCount);
} catch (Exception e1) {
e1.printStackTrace();
} finally {
try {//关闭连接
if (conn != null) {
conn.close();
}
} catch (Exception ex) {
}
return rCount;
}
}