2023年8月3日发(作者:)

jdbc数据批量更新update操作 java操作数据库批量更新主要为addBatch() 和executeBatch()⽅法,⼀般将数据存储在ArrayList⾥⾯,⼀次批量更新为⼀个addBatch(),全部更新完后,统⼀执⾏executeBatch()⽅法。⼀下为代码: public void UpdateData2(List list){ try { connection = getConnection(); String sqlStr = "update t_mas_tph set where TPHNUMBER=?"; pstm = eStatement(sqlStr); for (String[] strings : list) { if(==8){ ing(1, strings[1]); ing(2, strings[2]); ing(3,strings[3].split(",")[0] ); ing(4, strings[3].split(",")[1]); ing(5, strings[4]); ing(6, strings[5].split(",")[0]); ing(7, strings[5].split(",")[1]); ect(8, ChangeTime2Date(strings[6])); ing(9, strings[7]); ing(10,strings[0] );

}else{ continue; } ch(); } eBatch(); } catch (Exception e) { tackTrace(); }finally{ ReleaseResource(); } }TPHNAME=?,GENERATEPOSITION=?,GENERATELON=?,GENERATELAT=?,LANDPOSITION=?,LANDLON=?,LANDLAT=?,LOGINTIME

注:往数据库⾥⾯添加date类型数据时,需要⽤到String类型时间转化为date: public Object ChangeTime2Date(String timeStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); try { Date dateFormat =(timeStr); amp dateSQL = new amp(e()); return dateSQL; } catch (ParseException e) { tackTrace(); } return null; }

2023年8月3日发(作者:)

jdbc数据批量更新update操作 java操作数据库批量更新主要为addBatch() 和executeBatch()⽅法,⼀般将数据存储在ArrayList⾥⾯,⼀次批量更新为⼀个addBatch(),全部更新完后,统⼀执⾏executeBatch()⽅法。⼀下为代码: public void UpdateData2(List list){ try { connection = getConnection(); String sqlStr = "update t_mas_tph set where TPHNUMBER=?"; pstm = eStatement(sqlStr); for (String[] strings : list) { if(==8){ ing(1, strings[1]); ing(2, strings[2]); ing(3,strings[3].split(",")[0] ); ing(4, strings[3].split(",")[1]); ing(5, strings[4]); ing(6, strings[5].split(",")[0]); ing(7, strings[5].split(",")[1]); ect(8, ChangeTime2Date(strings[6])); ing(9, strings[7]); ing(10,strings[0] );

}else{ continue; } ch(); } eBatch(); } catch (Exception e) { tackTrace(); }finally{ ReleaseResource(); } }TPHNAME=?,GENERATEPOSITION=?,GENERATELON=?,GENERATELAT=?,LANDPOSITION=?,LANDLON=?,LANDLAT=?,LOGINTIME

注:往数据库⾥⾯添加date类型数据时,需要⽤到String类型时间转化为date: public Object ChangeTime2Date(String timeStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); try { Date dateFormat =(timeStr); amp dateSQL = new amp(e()); return dateSQL; } catch (ParseException e) { tackTrace(); } return null; }