xml解析记录

dom解析以及 sax 解析之后迎来换库,从oracle 换到sqlserver  没有虚拟表,不能批量插入了。

(oracle批量插入https://www.cnblogs.com/yaobolove/p/6237542.html)

由于sqlserver一次最多insert一千条数据 于是有了以下代码。记录一下。一只菜鸟,共勉

/**
 * 
 */
package com.thinkgem.jeesite.modules.projectmanage.handler;


import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
import com.thinkgem.jeesite.common.utils.SpringContextHolder;
import com.thinkgem.jeesite.modules.projectmanage.dao.JgbgjDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.JgbgyDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.KgbgjDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.KgbgyDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.SgjdDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.SgrwDao;
import com.thinkgem.jeesite.modules.projectmanage.dao.SgrzDao;
import com.thinkgem.jeesite.modules.projectmanage.entity.Jgbgj;
import com.thinkgem.jeesite.modules.projectmanage.entity.Jgbgy;
import com.thinkgem.jeesite.modules.projectmanage.entity.Kgbgj;
import com.thinkgem.jeesite.modules.projectmanage.entity.Kgbgy;
import com.thinkgem.jeesite.modules.projectmanage.entity.Sgjd;
import com.thinkgem.jeesite.modules.projectmanage.entity.Sgrw;
import com.thinkgem.jeesite.modules.projectmanage.entity.Sgrz;
import com.thinkgem.jeesite.modules.projectmanage.util.C3P0Util;


/**
 * @Description:
 * @Author: 杨舜玺
 * @Company:
 * @CreateDate: 2018-3-30
 */


public class BatchSaveHandler extends DefaultHandler{

private static JgbgjDao jgbgjDao = SpringContextHolder.getBean(JgbgjDao.class);
private static JgbgyDao jgbgyDao = SpringContextHolder.getBean(JgbgyDao.class);
private static KgbgjDao kgbgjDao = SpringContextHolder.getBean(KgbgjDao.class);
private static KgbgyDao kgbgyDao = SpringContextHolder.getBean(KgbgyDao.class);
private static SgjdDao sgjdDao = SpringContextHolder.getBean(SgjdDao.class);
private static SgrzDao sgrzDao = SpringContextHolder.getBean(SgrzDao.class);
private static SgrwDao sgrwDao = SpringContextHolder.getBean(SgrwDao.class);

Sgrw sgrw = null;
Sgrz sgrz = null;
Jgbgj jgbgj = null;
Jgbgy jgbgy = null;
Kgbgj kgbgj = null;
Kgbgy kgbgy = null;
Sgjd sgjd = null;


int flag = 0;
static Integer id = 10000;
List sgrwList = new ArrayList();
List sgrzList = new ArrayList();
List jgbgjList = new ArrayList();
List jgbgyList = new ArrayList();
List kgbgjList = new ArrayList();
List kgbgyList = new ArrayList();
List sgjdList = new ArrayList();


//static{
DateFormat timedf = new SimpleDateFormat("yyyy-MM-dd");
//}

String value = "";
private StringBuilder sb;
// xml读取的时间类型需要Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 小写的mm表示的是分钟


StringBuffer sgrwSql = new StringBuffer("insert into t_sgrw (id,djbh,rq,rwzt,gznr,sgdw,sgry,gcdz,sgdw1,rwxs,gzfzr,dwfzr,jhks,jhwc,qfrq,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer sgrzSql = new StringBuffer("insert into t_sgrz (id,djbh,rq,gznr,sgy,rwxc,gzfzr,dwfzr,kld,dw,xczyrs,sjwcsj,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer jgbgjSql = new StringBuffer("insert into t_jgbgj (id,djbh,rq,sgy,zt,sgdw,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer jgbgySql = new StringBuffer("insert into t_jgbgy (id,djbh,rq,zt,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer kgbgjSql = new StringBuffer("insert into t_kgbgj (id,djbh,rq,sgy,zt,sgdw,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer kgbgySql = new StringBuffer("insert into t_kgbgy (id,djbh,rq,zt,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
StringBuffer sgjdSql = new StringBuffer("insert into t_sgjd (id,djbh,rq,zt,sgy,gkdj,tjr,tjsj,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");

@Override
public void startDocument() throws SAXException {
super.startDocument();
System.out.println("SAX解析开始");
sgjdDao.deleteGc();
kgbgjDao.deleteGc();
jgbgjDao.deleteGc();
kgbgyDao.deleteGc();
jgbgyDao.deleteGc();
sgrwDao.deleteGc();
sgrzDao.deleteGc();
}




@Override
public void endDocument() throws SAXException {
super.endDocument();
System.out.println("SAX解析结束");

//第一步:创建连接池核心工具类
C3P0Util dataSource=new C3P0Util();
PreparedStatement ps = null;

try {

Connection con = dataSource.getConnection();

//把最后一组数据加入list中
sgjdList.add(sgjdSql.toString());
kgbgjList.add(kgbgjSql.toString());
jgbgjList.add(jgbgjSql.toString());
kgbgyList.add(kgbgySql.toString());
jgbgyList.add(jgbgySql.toString());
sgrwList.add(sgrwSql.toString());
sgrzList.add(sgrzSql.toString());

for (int i=0;i<sgjdList.size();i++) {
String object = sgjdList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}
for (int i=0;i<kgbgjList.size();i++) {
String object = kgbgjList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}
for (int i=0;i<jgbgjList.size();i++) {
String object = jgbgjList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}
for (int i=0;i<kgbgyList.size();i++) {
String object = kgbgyList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}
for (int i=0;i<jgbgyList.size();i++) {
String object = jgbgyList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}
for (int i=0;i<sgrwList.size();i++) {
String object = sgrwList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}for (int i=0;i<sgrzList.size();i++) {
String object = sgrzList.get(i).toString();
ps=con.prepareStatement(object.substring(0, object.length()-1)); //去掉sql字符串最后一个逗号
ps.execute();
}

dataSource.release(con, ps, null);

} catch (SQLException e) {
e.printStackTrace();
}
}

/* 开始解析xml 子标签
*/
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// 调用DefaultHandler类的startElement方法
super.startElement(uri, localName, qName, attributes);
//施工交底
if (qName.equals("sgjd")) {
sgjd = new Sgjd();
sgjd.preInsert();
sgjd.setDelFlag("0");
sgjd.setCreateDate(new Date());
sgjdSql.append("("+ sgjd.getId()+",");

}
//开工报告甲
if (qName.equals("kgbgj")) {
kgbgj = new Kgbgj();
kgbgj.preInsert();
kgbgj.setDelFlag("0");
kgbgj.setCreateDate(new Date());
kgbgjSql.append("("+ kgbgj.getId()+",");

}
//竣工报告甲:jgbgj
if (qName.equals("jgbgj")) {
jgbgj = new Jgbgj();
jgbgj.preInsert();
jgbgj.setDelFlag("0");
jgbgj.setCreateDate(new Date());
jgbgjSql.append("("+ jgbgj.getId()+",");

}
//开工报告乙:kgbgy
if (qName.equals("kgbgy")) {
kgbgy = new Kgbgy();
kgbgy.preInsert();
kgbgy.setDelFlag("0");
kgbgy.setCreateDate(new Date());
kgbgySql.append("("+ kgbgy.getId()+",");

}
//竣工报告乙:jgbgy
if (qName.equals("jgbgy")) {
jgbgy = new Jgbgy();
jgbgy.preInsert();
jgbgy.setDelFlag("0");
jgbgy.setCreateDate(new Date());
jgbgySql.append("("+ jgbgy.getId()+",");

}
//施工任务:sgrw
if (qName.equals("sgrw")) {
sgrw = new Sgrw();
sgrw.preInsert();
sgrw.setDelFlag("0");
sgrw.setCreateDate(new Date());
sgrwSql.append("("+ sgrw.getId()+",");

}
//施工日志:sgrz
if (qName.equals("sgrz")) {
sgrz = new Sgrz();
sgrz.preInsert();
sgrz.setDelFlag("0");
sgrz.setCreateDate(new Date());
sgrzSql.append("("+ sgrz.getId()+",");

}

sb = new StringBuilder();

}


@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// 调用DefaultHandler类的endElement方法
super.endElement(uri, localName, qName);
try {
//施工任务:sgrw
if(sgrw !=null){
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
// sgrw 标签结束时 所作的操作
if (qName.equals("sgrw") && flag<999) {

sgrwSql.append("'").append(sgrw.getDjbh()!=null?sgrw.getDjbh():"").append("',")
   .append(sgrw.getRq() !=null?"CONVERT(datetime,"+timedf.format(sgrw.getRq())+")":"null").append(",")
   .append("'").append(sgrw.getRwzt()!=null?sgrw.getRwzt():"").append("',")
   .append("'").append(sgrw.getGznr()!=null?sgrw.getGznr():"").append("',")
   .append("'").append(sgrw.getSgdw()!=null?sgrw.getSgdw():"").append("',")
   .append("'").append(sgrw.getSgry()!=null?sgrw.getSgry():"").append("',")
   .append("'").append(sgrw.getGcdz()!=null?sgrw.getGcdz():"").append("',")
   .append("'").append(sgrw.getSgdw1()!=null?sgrw.getSgdw1():"").append("',")
   .append("'").append(sgrw.getRwxs()!=null?sgrw.getRwxs():"").append("',")
   .append("'").append(sgrw.getGzfzr()!=null?sgrw.getGzfzr():"").append("',")
   .append("'").append(sgrw.getDwfzr()!=null?sgrw.getDwfzr():"").append("',")
   .append(sgrw.getJhks() !=null?"CONVERT(datetime,"+timedf.format(sgrw.getJhks())+")":"null").append(",")
   .append(sgrw.getJhwc() !=null?"CONVERT(datetime,"+timedf.format(sgrw.getJhwc())+")":"null").append(",")
   .append(sgrw.getQfrq() !=null?"CONVERT(datetime,"+timedf.format(sgrw.getQfrq())+")":"null").append(",")
   .append("'").append(sgrw.getGcbh()!=null?sgrw.getGcbh():"").append("',")
   .append("'").append(sgrw.getGczh()!=null? sgrw.getGczh(): "").append("',")
   .append("'").append(sgrw.getDuojingId()!=null?sgrw.getDuojingId():"").append("',")
   .append("'").append(sgrw.getDelFlag() !=null?sgrw.getDelFlag(): "0").append("',")
   .append(sgrw.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(sgrw.getCreateDate())+")":"null").append("),");

sgrw=null;
flag++;

}if(qName.equals("sgrw") && flag>998){
//数据达到一千条    清空sql  标记 set 0
sgrwList.add(sgrwSql.toString());
sgrwSql.setLength(0);
sgrwSql.append("insert into t_sgrw (id,djbh,rq,rwzt,gznr,sgdw,sgry,gcdz,sgdw1,rwxs,gzfzr,dwfzr,jhks,jhwc,qfrq,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
if(!value.equals("") && value != null){
sgrw.setDjbh(value);
}
}
else if(qName.equals("rq")){
if(!value.equals("") && value != null){
sgrw.setRq(sdf.parse(value));
}
}
else if(qName.equals("rwzt")){
if(!value.equals("") && value != null){
sgrw.setRwzt(value);
}
}
else if(qName.equals("gznr")){
if(!value.equals("") && value != null){
sgrw.setGznr(value);
}
}
else if(qName.equals("sgdw")){
if(!value.equals("") && value != null){
sgrw.setSgdw(value);
}
}
else if(qName.equals("sgry")){
if(!value.equals("") && value != null){
sgrw.setSgry(value);
}
}
else if(qName.equals("gcdz")){
if(!value.equals("") && value != null){
sgrw.setGcdz(value);
}
}
else if(qName.equals("sgdw1")){
if(!value.equals("") && value != null){
sgrw.setSgdw1(value);
}
}
else if(qName.equals("rwxs")){
if(!value.equals("") && value != null){
sgrw.setRwxs(value);
}
}
else if(qName.equals("jhks")){
if(!value.equals("") && value != null){
sgrw.setJhks(sdf.parse(value));
}
}
else if(qName.equals("jhwc")){
if(!value.equals("") && value != null){
sgrw.setJhwc(sdf.parse(value));
}
}
else if(qName.equals("gcbh")){
if(!value.equals("") && value != null){
sgrw.setGcbh(value);
}
}
else if (qName.equals("gczh")) {
if(!value.equals("") && value != null){
sgrw.setGczh(value);
}
}
else if (qName.equals("duojing_id")) {
if(!value.equals("") && value != null){
sgrw.setDuojingId(value);
}
}
}
//施工日志:sgrz
if(sgrz !=null){
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
if (qName.equals("sgrz") && flag<999) {

sgrzSql.append("'").append(sgrz.getDjbh()!=null?sgrz.getDjbh():"").append("',")
   .append(sgrz.getRq() !=null?"CONVERT(datetime,"+timedf.format(sgrz.getRq())+")":"null").append(",")
   .append("'").append(sgrz.getGznr()!=null?sgrz.getGznr():"").append("',")
   .append("'").append(sgrz.getSgy()!=null?sgrz.getSgy():"").append("',")
   .append("'").append(sgrz.getRwxc()!=null?sgrz.getRwxc():"").append("',")
   .append("'").append(sgrz.getGzfzr()!=null?sgrz.getGzfzr():"").append("',")
   .append("'").append(sgrz.getDwfzr()!=null?sgrz.getDwfzr():"").append("',")
   .append("'").append(sgrz.getKld()!=null?sgrz.getKld():"").append("',")
   .append("'").append(sgrz.getDw()!=null?sgrz.getDw():"").append("',")
   .append("'").append(sgrz.getXczyrs()!=null?sgrz.getXczyrs():0).append("',")
   .append(sgrz.getSjwcsj() !=null?"CONVERT(datetime,"+timedf.format(sgrz.getSjwcsj())+")":"null").append(",")
   .append("'").append(sgrz.getGcbh()!=null?sgrz.getGcbh():"").append("',")
   .append("'").append(sgrz.getGczh()!=null? sgrz.getGczh(): "").append("',")
   .append("'").append(sgrz.getDuojingId()!=null?sgrz.getDuojingId():"").append("',")
   .append("'").append(sgrz.getDelFlag() !=null?sgrz.getDelFlag(): "0").append("',")
   .append(sgrz.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(sgrz.getCreateDate())+")":"null").append("),");

sgrz=null;
flag++;
}if(qName.equals("sgrz") && flag>998){
//数据达到一千条    清空sql  标记 set 0
sgrzList.add(sgrzSql.toString());
sgrzSql.setLength(0);
sgrzSql.append("insert into t_sgrz (id,djbh,rq,gznr,sgy,rwxc,gzfzr,dwfzr,kld,dw,xczyrs,sjwcsj,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
sgrz.setDjbh(value);
}
else if(qName.equals("rq")){
sgrz.setRq(sdf.parse(value));
}
else if(qName.equals("gznr")){
sgrz.setGznr(value);
}
else if(qName.equals("sgy")){
sgrz.setSgy(value);
}
else if(qName.equals("rwxc")){
sgrz.setRwxc(value);
}
else if(qName.equals("gzfzr")){
sgrz.setGzfzr(value);
}
else if(qName.equals("dwfzr")){
sgrz.setDwfzr(value);
}
else if(qName.equals("kld")){
sgrz.setKld(value);
}
else if(qName.equals("dw")){
sgrz.setDw(value);
}
else if(qName.equals("xczyrs")){
sgrz.setXczyrs(value);
}
else if(qName.equals("sjwcsj")){
sgrz.setSjwcsj(sdf.parse(value));
}
else if(qName.equals("gcbh")){
sgrz.setGcbh(value);
}
else if (qName.equals("gczh")) {
sgrz.setGczh(value);
}
else if (qName.equals("duojing_id")) {
sgrz.setDuojingId(value);
}
}
//施工交底
if (sgjd !=null) { //当对象不为空时 ,表示开始解析 以 sgjd 标签开头的标签
//获取   sgjd 标签中的每一个小标签值
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
//以  jgbgj 结束 的标签表示一条数据 解析完成
//    !=null?sgjd.getZt():""
if (qName.equals("sgjd") && flag<999) {

sgjdSql.append("'").append(sgjd.getDjbh()!=null?sgjd.getDjbh():"").append("',")
   .append(sgjd.getRq() !=null?"CONVERT(datetime,"+timedf.format(sgjd.getRq())+")":"null").append(",")
   .append("'").append(sgjd.getZt()!=null?sgjd.getZt():"").append("',")
   .append("'").append(sgjd.getSgy()!=null?sgjd.getSgy():"").append("',")
   .append("'").append(sgjd.getGkdj()!=null?sgjd.getGkdj():"").append("',")
   .append("'").append(sgjd.getTjr()!=null?sgjd.getTjr():"").append("',")
   .append(sgjd.getTjsj() !=null?"CONVERT(datetime,"+timedf.format(sgjd.getTjsj())+")":"null").append(",")
   .append("'").append(sgjd.getGcbh()!=null?sgjd.getGcbh():"").append("',")
   .append("'").append(sgjd.getGczh()!=null? sgjd.getGczh(): "").append("',")
   .append("'").append(sgjd.getDuojingId()!=null?sgjd.getDuojingId():"").append("',")
   .append("'").append(sgjd.getDelFlag() !=null?sgjd.getDelFlag(): "0").append("',")
   .append(sgjd.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(sgjd.getCreateDate())+")":"null").append("),");
sgjd=null;
flag++;
}if(qName.equals("sgjd") && flag>998){
//数据达到一千条    清空sql  标记 set 0
sgjdList.add(sgjdSql.toString());
sgjdSql.setLength(0);
sgjdSql.append("insert into t_sgjd (id,djbh,rq,zt,sgy,gkdj,tjr,tjsj,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if (qName.equals("djbh")) {
sgjd.setDjbh(value);
}
else if (qName.equals("rq")) {
sgjd.setRq(sdf.parse(value));
}
else if (qName.equals("zt")) {
sgjd.setZt(value);
}
else if (qName.equals("sgy")) {
sgjd.setSgy(value);
}
else if (qName.equals("gkdj")) {
sgjd.setGkdj(value);
}
else if (qName.equals("tjr")) {
sgjd.setTjr(value);
}
else if (qName.equals("tjsj")) {
sgjd.setTjsj(sdf.parse(value));
}
else if (qName.equals("gcbh")) {
sgjd.setGcbh(value);
}
else if (qName.equals("gczh")) {
sgjd.setGczh(value);
}
else if (qName.equals("duojing_id")) {
sgjd.setDuojingId(value);
}
}
//开工报告甲
if (kgbgj !=null){
//获取   kgbgj 标签中的每一个小标签值
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
//以  kgbgj 结束 的标签表示一条数据 解析完成
if (qName.equals("kgbgj") && flag<999) {

kgbgjSql.append("'").append(kgbgj.getDjbh()!=null?kgbgj.getDjbh():"").append("',")
   .append(kgbgj.getRq() !=null?"CONVERT(datetime,"+timedf.format(kgbgj.getRq())+")":"null").append(",")
   .append("'").append(kgbgj.getSgy()!=null?kgbgj.getSgy():"").append("',")
   .append("'").append(kgbgj.getZt()!=null?kgbgj.getZt():"").append("',")
   .append("'").append(kgbgj.getSgdw()!=null?kgbgj.getSgdw():"").append("',")
   .append(kgbgj.getJhkg() !=null?"CONVERT(datetime,"+timedf.format(kgbgj.getJhkg())+")":"null").append(",")
   .append(kgbgj.getJhjg() !=null?"CONVERT(datetime,"+timedf.format(kgbgj.getJhjg())+")":"null").append(",")
   .append(kgbgj.getSjkg() !=null?"CONVERT(datetime,"+timedf.format(kgbgj.getSjkg())+")":"null").append(",")
   .append("'").append(kgbgj.getGcbh()!=null?kgbgj.getGcbh():"").append("',")
   .append("'").append(kgbgj.getGczh()!=null? kgbgj.getGczh(): "").append("',")
   .append("'").append(kgbgj.getDuojingId()!=null?kgbgj.getDuojingId():"").append("',")
   .append("'").append(kgbgj.getDelFlag() !=null?kgbgj.getDelFlag(): "0").append("',")
   .append(kgbgj.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(kgbgj.getCreateDate())+")":"null").append("),");
kgbgj=null;
flag++;
}if(qName.equals("kgbgj") && flag>998){
//数据达到一千条    清空sql  标记 set 0
kgbgjList.add(kgbgjSql.toString());
kgbgjSql.setLength(0);
kgbgjSql.append("insert into t_kgbgj (id,djbh,rq,sgy,zt,sgdw,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
kgbgj.setDjbh(value);
}
else if(qName.equals("rq")){
kgbgj.setRq(sdf.parse(value));
}
else if(qName.equals("sgy")){
kgbgj.setSgy(value);
}
else if(qName.equals("zt")){
kgbgj.setZt(value);
}
else if(qName.equals("sgdw")){
kgbgj.setSgdw(value);
}
else if(qName.equals("jhkg")){
kgbgj.setJhkg(sdf.parse(value));
}
else if(qName.equals("jhjg")){
kgbgj.setJhjg(sdf.parse(value));
}
else if(qName.equals("gcbh")){
kgbgj.setGcbh(value);
}
else if (qName.equals("gczh")) {
if(!value.equals("") && value != null){
kgbgj.setGczh(value);
}
}
else if (qName.equals("duojing_id")) {
if(!value.equals("") && value != null){
kgbgj.setDuojingId(value);
}
}

}

//竣工报告甲
if(jgbgj !=null){
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
if (qName.equals("jgbgj") && flag<999) {

jgbgjSql.append("'").append(jgbgj.getDjbh()!=null?jgbgj.getDjbh():"").append("',")
   .append(jgbgj.getRq() !=null?"CONVERT(datetime,"+timedf.format(jgbgj.getRq())+")":"null").append(",")
   .append("'").append(jgbgj.getSgy()!=null?jgbgj.getSgy():"").append("',")
   .append("'").append(jgbgj.getZt()!=null?jgbgj.getZt():"").append("',")
   .append("'").append(jgbgj.getSgdw()!=null?jgbgj.getSgdw():"").append("',")
   .append(jgbgj.getJhkg() !=null?"CONVERT(datetime,"+timedf.format(jgbgj.getJhkg())+")":"null").append(",")
   .append(jgbgj.getJhjg() !=null?"CONVERT(datetime,"+timedf.format(jgbgj.getJhjg())+")":"null").append(",")
   .append(jgbgj.getSjkg() !=null?"CONVERT(datetime,"+timedf.format(jgbgj.getSjkg())+")":"null").append(",")
   .append("'").append(jgbgj.getGcbh()!=null?jgbgj.getGcbh():"").append("',")
   .append("'").append(jgbgj.getGczh()!=null? jgbgj.getGczh(): "").append("',")
   .append("'").append(jgbgj.getDuojingId()!=null?jgbgj.getDuojingId():"").append("',")
   .append("'").append(jgbgj.getDelFlag() !=null?jgbgj.getDelFlag(): "0").append("',")
   .append(jgbgj.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(jgbgj.getCreateDate())+")":"null").append("),");

jgbgj=null;
flag++;

}if(qName.equals("jgbgj") && flag>998){
//数据达到一千条    清空sql  标记 set 0
jgbgjList.add(jgbgjSql.toString());
jgbgjSql.setLength(0);
jgbgjSql.append("insert into t_jgbgj (id,djbh,rq,sgy,zt,sgdw,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
jgbgj.setDjbh(value);
}
else if(qName.equals("rq")){
jgbgj.setRq(sdf.parse(value));
}
else if(qName.equals("sgy")){
jgbgj.setSgy(value);
}
else if(qName.equals("zt")){
jgbgj.setZt(value);
}
else if(qName.equals("sgdw")){
jgbgj.setSgdw(value);
}
else if(qName.equals("jhkg")){
jgbgj.setJhkg(sdf.parse(value));
}
else if(qName.equals("jhjg")){
jgbgj.setJhjg(sdf.parse(value));
}
else if(qName.equals("gcbh")){
jgbgj.setGcbh(value);
}
else if (qName.equals("gczh")) {
if(!value.equals("") && value != null){
jgbgj.setGczh(value);
}
}
else if (qName.equals("duojing_id")) {
if(!value.equals("") && value != null){
jgbgj.setDuojingId(value);
}
}
}
//开工报告乙:kgbgy
if(kgbgy!=null){
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
if (qName.equals("kgbgy") && flag<999) {

kgbgySql.append("'").append(kgbgy.getDjbh()!=null?kgbgy.getDjbh():"").append("',")
   .append(kgbgy.getRq() !=null?"CONVERT(datetime,"+timedf.format(kgbgy.getRq())+")":"null").append(",")
   .append("'").append(kgbgy.getZt()!=null?kgbgy.getZt():"").append("',")
   .append(kgbgy.getJhkg() !=null?"CONVERT(datetime,"+timedf.format(kgbgy.getJhkg())+")":"null").append(",")
   .append(kgbgy.getJhjg() !=null?"CONVERT(datetime,"+timedf.format(kgbgy.getJhjg())+")":"null").append(",")
   .append(kgbgy.getSjkg() !=null?"CONVERT(datetime,"+timedf.format(kgbgy.getSjkg())+")":"null").append(",")
   .append("'").append(kgbgy.getGcbh()!=null?kgbgy.getGcbh():"").append("',")
   .append("'").append(kgbgy.getGczh()!=null? kgbgy.getGczh(): "").append("',")
   .append("'").append(kgbgy.getDuojingId()!=null?kgbgy.getDuojingId():"").append("',")
   .append("'").append(kgbgy.getDelFlag() !=null?kgbgy.getDelFlag(): "0").append("',")
   .append(kgbgy.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(kgbgy.getCreateDate())+")":"null").append("),");

kgbgy=null;
flag++;

}if(qName.equals("kgbgy") && flag>998){
//数据达到一千条    清空sql  标记 set 0
kgbgyList.add(kgbgySql.toString());
kgbgySql.setLength(0);
kgbgySql.append("insert into t_kgbgy (id,djbh,rq,zt,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
kgbgy.setDjbh(value);
}
else if(qName.equals("rq")){
kgbgy.setRq(sdf.parse(value));
}
else if(qName.equals("zt")){
kgbgy.setZt(value);
}
else if(qName.equals("jhkg")){
kgbgy.setJhkg(sdf.parse(value));
}
else if(qName.equals("jhjg")){
kgbgy.setJhjg(sdf.parse(value));
}
else if(qName.equals("sjkg")){
kgbgy.setSjkg(sdf.parse(value));
}
else if(qName.equals("gcbh")){
kgbgy.setGcbh(value);
}
else if (qName.equals("gczh")) {
if(!value.equals("") && value != null){
kgbgy.setGczh(value);
}
}
else if (qName.equals("duojing_id")) {
if(!value.equals("") && value != null){
kgbgy.setDuojingId(value);
}
}

}
//竣工报告乙:jgbgy
if(jgbgy!=null){
if (!sb.equals("") && sb != null) {
value = sb.toString();
}
if (qName.equals("jgbgy") && flag<999) {

jgbgySql.append("'").append(jgbgy.getDjbh()!=null?jgbgy.getDjbh():"").append("',")
   .append(jgbgy.getRq() !=null?"CONVERT(datetime,"+timedf.format(jgbgy.getRq())+")":"null").append(",")
   .append("'").append(jgbgy.getZt()!=null?jgbgy.getZt():"").append("',")
   .append(jgbgy.getJhkg() !=null?"CONVERT(datetime,"+timedf.format(jgbgy.getJhkg())+")":"null").append(",")
   .append(jgbgy.getJhjg() !=null?"CONVERT(datetime,"+timedf.format(jgbgy.getJhjg())+")":"null").append(",")
   .append(jgbgy.getSjkg() !=null?"CONVERT(datetime,"+timedf.format(jgbgy.getSjkg())+")":"null").append(",")
   .append("'").append(jgbgy.getGcbh()!=null?jgbgy.getGcbh():"").append("',")
   .append("'").append(jgbgy.getGczh()!=null? jgbgy.getGczh(): "").append("',")
   .append("'").append(jgbgy.getDuojingId()!=null?jgbgy.getDuojingId():"").append("',")
   .append("'").append(jgbgy.getDelFlag() !=null?jgbgy.getDelFlag(): "0").append("',")
   .append(jgbgy.getCreateDate() !=null?"CONVERT(datetime,"+timedf.format(jgbgy.getCreateDate())+")":"null").append("),");

jgbgy=null;
flag++;

}if(qName.equals("jgbgy") && flag>998){
//数据达到一千条    清空sql  标记 set 0
jgbgyList.add(jgbgySql.toString());
jgbgySql.setLength(0);
jgbgySql.append("insert into t_jgbgy (id,djbh,rq,zt,jhkg,jhjg,sjkg,gcbh,gczh,duojing_id,DEL_FLAG,CREATE_DATE) values");
flag=0;
}
else if(qName.equals("djbh")){
jgbgy.setDjbh(value);
}
else if(qName.equals("rq")){
jgbgy.setRq(sdf.parse(value));
}
else if(qName.equals("zt")){
jgbgy.setZt(value);
}
else if(qName.equals("jhkg")){
jgbgy.setJhkg(sdf.parse(value));
}
else if(qName.equals("jhjg")){
jgbgy.setJhjg(sdf.parse(value));
}
else if(qName.equals("sjkg")){
jgbgy.setSjkg(sdf.parse(value));
}
else if(qName.equals("gcbh")){
jgbgy.setGcbh(value);
}
else if (qName.equals("gczh")) {
if(!value.equals("") && value != null){
jgbgy.setGczh(value);
}
}
else if (qName.equals("duojing_id")) {
if(!value.equals("") && value != null){
jgbgy.setDuojingId(value);
}
}
}


} catch (ParseException e) {
e.printStackTrace();
}

}

@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
super.characters(ch, start, length);
//节点值
sb.append(new String(ch, start, length));
}






static String generateUUId(){

String uuid = UUID.randomUUID().toString().replaceAll("-", "");

return uuid;
}


static String generateId(){
id++;
return id.toString();
}






}



阅读更多

没有更多推荐了,返回首页