public class ServiceImpl implements Service{
@Autowired
private DBUtil db;
@Resource(name="jdbcTemplateTDS")
private JdbcTemplate jdbcTemplateIDS;
@Override
public void ladData(List<ZFIRPYEBO>packageIdList,SysDatasourceBO sysDatasourceBO) {
String jdbc_url = db.getJdbc_url();
String jdbc_username = db.getJdbc_username();
String jdbc_password = db.getJdbc_password ();
String driverName = db.getDriverName();
Connection conn = null;
PreparedStatement ps = null;
StringBuffer sqlbuffer = new StringBuffer();
try{
Driver.class.forName(diverName);
conn = DriverManager.getConnection(jdbc_url ,jdbc_username ,jdbc_password );
sqlbuffer.append("INSERT INTO TABLE(A)");
sqlbuffer.append("values");
sqlbuffer.append("(?)");
ps = conn.prepareStatement(sqlbuffer.toString);
BO bo = null;
for(int i=0;i<list.size();i++){
bo = list.get(i);
if(StringUtil.isNotEmpty(bo.getA())){
ps.setString(1,bo.getA());
}else{
ps.setString(1,"");
}
ps.addBatch();//添加批量提交,可设置不同的大小
if((i!=0 && i%1000==0)){
ps.executeBatch();
conn.commit();
ps.clearBatch();
}
ps.executeBatch();
conn.commit();
ps.clearBatch();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(conn != null){
conn.close();
}
if(ps!= null){
ps.close();
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}