All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sql.OrgAuthor Maven / Gradle / Ivy

The newest version!
package sql;

import org.apache.commons.dbutils.handlers.MapListHandler;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * unclewang
 * 2018/4/3 16:27
 */
public class OrgAuthor {
    public static void main(String[] args) {
        DbUtilsDruid dbUtil = DbUtilsDruid.getInstance();
        Set authororg = new HashSet<>();

        List> authors = (List>) dbUtil.query(dbUtil.getCon(), "Select * from expert", new MapListHandler());

        for (Map map : authors) {
            try {
                String author = ((String) map.get("authorCn")).replace("!", " ").replaceAll("[ \t\r\n]", "");
                String org = ((String) map.get("organ")).replace("!", " ").replaceAll("[ \t\r\n]", "");
//                    System.out.println(author + "@@@@" + org);
                String[] as = author.split("[;,,]");
                String[] os = org.split("[;,,]");
                if (as.length > 1 && os.length == 1) {
                    for (int i = 0; i < as.length; i++) {
                        authororg.add(as[i] + ";" + os[0]);
                    }
                } else if (as.length <= os.length) {
                    for (int i = 0; i < as.length; i++) {
                        authororg.add(as[i] + ";" + os[i]);
                    }
                } else if (as.length > os.length) {
                    for (int i = 0; i < os.length; i++) {
                        authororg.add(as[i] + ";" + os[i]);
                    }
                }
            } catch (NullPointerException e) {
                continue;
            }

        }


        authororg.forEach(s -> {
            try {
                System.out.println(s);
                //FileUtils.write(new File("author_org.txt"), s+"\n", "utf-8", true);
                if (s.split(";").length == 2) {
                    dbUtil.crud("INSERT INTO author(author,org) VALUES(?,?)", s.split(";"));
                } else {
                    return;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy