SQL语句拼装

来源:互联网 发布:浏览器重新加载js 编辑:程序博客网 时间:2024/04/29 09:44

按照毕业设计的需求,在Excel数据与数据库信息交互设计中,需要通过一个XML文档指定Excel列要导入数据表的那个属性,如下图,(实际运用中必须要有数据库字段的类型,来判断是否需要加引号或者格式数据,如果没有数据字段类型,Insert语句会出错,。。select语句不需要考虑。)

 

1、首先需要读取XML文档,用字符数组纪录获得的信息。返回的数组样式a0aN

xsb,xscj,学号,姓名,性别,出生时间,专业号,分数,备注,xh,xm,xb,cssj,zy_id,zxf,bz

 

代码

           DocumentBuilderFactory factory = DocumentBuilderFactory

                  .newInstance();

           DocumentBuilder builder = factory.newDocumentBuilder();

           Document document = builder.parse(new File("D:\\xscj_xsb.xml"));

           String version = document.getXmlVersion();//xscj_xsb test_kcb

           String encoding = document.getXmlEncoding();

           System.out.println(version);

           System.out.println(encoding);

           Element root = document.getDocumentElement();

           String rootName = root.getNodeName();

           System.out.println("XML根节点的名称为: " + rootName);

           NodeList nodelist = document.getElementsByTagName("property");// 获取节点的集合

           int size = nodelist.getLength();

           xlsdb = new String[2 * size + 2];

           xlsdb[0]=root.getAttribute("name");

           xlsdb[1]=root.getAttribute("catalog");

           for (int i = 0; i < size; i++) {

              Node node = nodelist.item(i);// 获取节点

              String nodeValue = node.getAttributes().getNamedItem("name")

                     .getNodeValue();

              xlsdb[i + 2] = nodeValue;

              String nodeValue2 =node.getFirstChild().getNextSibling()

                     .getAttributes().getNamedItem("name").getNodeValue();

              xlsdb[size + 2 + i] = nodeValue2;

           }

      

2、使用StringBuilder,用for循环append添加到语句最后,。。