//内容经供参考,以下代码是运行成功后的结果.切莫copy,拒绝只做理论帝,努力成为手工王,高手请留言,让大家一起学习进步,壮大我大程序员
//此方法基于我之前发布的DBSql类文件而做的一个方法,用来更新数据库的数据集,
//多条记录保存在内存当中,让 addBatch();添加进去,一次执行通过,这样节省了资源.
public boolean InsertU8(){
String U8sql="select CUSTDH,95,ID,'01',DATE,PINO ,ZBFL,CREATEUSER,'美金','6.12','0.12',REMARK,0,'USERNAME',0,'自定义10',0,'CUSTNAME',0,'PITYPE' "+
"from GAJAH.dbo.BO_OM_PI where PINO not in (select cSOCode from so_somain)";
// String sql2="insert into so_somain (cCusCode,iVTid,id,cSTCode,dDate,cSOCode,cDepCode,cPersonCode,cexch_name,iExChRate,iTaxRate,"
// +"cMemo, iStatus,cMaker,bDisFlag,cDefine10,bReturnFlag,cCusName,bOrder,cBusType) "+
// "select CUSTDH,95,ID,'01',DATE,PINO ,ZBFL,CREATEUSER,'美金','6.12','0.12',REMARK,0,'USERNAME',0,'自定义10',0,'CUSTNAME',0,'PITYPE' "+
// "from GAJAH.dbo.BO_OM_PI where PINO not in (select cSOCode from so_somain)";
String sql2="insert into so_somain (cCusCode,iVTid,id,cSTCode,dDate,cSOCode,cDepCode,cPersonCode,cexch_name,iExChRate,iTaxRate,"
+"cMemo, iStatus,cMaker,bDisFlag,cDefine10,bReturnFlag,cCusName,bOrder,cBusType) value(?,";
for(int i=1;i<19;i++){
sql2=sql2+"?,";
}
sql2=sql2+"?)";
//以上生成对应的sql语句
System.out.println(sql2);
Connection conn = U8DBSql.getConnecton();
PreparedStatement pst = null;
try {
List U8list=U8DBSql.GetLIst(U8sql, 20); //list得到当前的数据集合,20表示字段数量,做赋值的时候循环的次数
pst = conn.prepareStatement(sql2);
ResultSet rs = null;
for(List OAuplist: U8list){//这个是循环list对象时候将值取出来,当然也可以申明一个对象,
//将值赋值给对象
for(int i=0;i<11;i++){
int t=i+1;
pst.setString(t, (String) OAuplist.get(i));
}
pst.addBatch();
}
int[] a=pst.executeBatch(); //最终执行一次连接最有效率的方法
System.out.println("执行"+a.length+"条记录");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}