Iterator iter = map.entrySet().iterator();
Connection con=DBConnection.getConnection();
while (iter.hasNext()) {
PreparedStatement pst=null;
String updatesql="update equipservice set service_is=1 where euipId=?";
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
try {
pst.setInt(1, Integer.parseInt(key.toString()));
pst.executeUpdate();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Connection con=DBConnection.getConnection();
while (iter.hasNext()) {
PreparedStatement pst=null;
String updatesql="update equipservice set service_is=1 where euipId=?";
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
try {
pst.setInt(1, Integer.parseInt(key.toString()));
pst.executeUpdate();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Connection setAutocommit(true/false);
PreparedStatement addBatch(); excuteBatch();
update A set cc=1 where aa in ('',''...) 后面那个括号里的
你用个循环拼个字符串就可以
但字符长度好像有限制
几十跳可以 多了数据库会报SQL语句太长的错误
try {
pst=con.prepareStatement(upsql);
for(int i=0;i <list.size();i++){
pst.setInt(1, Integer.parseInt(list.get(i).toString()));
pst.addBatch();
}
pst.executeBatch(); } catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我把代码改成这样,但好像只能只能执行一次,我跑到数据库中把修改过的改了一下,发现就不能修改了,除非把myeclipse重启。