diff --git a/src/osm/jp/coverage/busstop/DbBusstop.java b/src/osm/jp/coverage/busstop/DbBusstop.java index f580b1c..28e55bb 100644 --- a/src/osm/jp/coverage/busstop/DbBusstop.java +++ b/src/osm/jp/coverage/busstop/DbBusstop.java @@ -6,6 +6,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLSyntaxErrorException; +import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -15,8 +16,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import static osm.jp.coverage.busstop.Busstop.showBusStop; -import static osm.jp.coverage.busstop.Busstop.showED01; +import static osm.jp.coverage.busstop.Busstop.anaComm; public class DbBusstop { public static final String TABLE_NAME = "bus_stop"; @@ -280,6 +280,72 @@ } /** + * + * @param con + * @param node + * @param iFileName // ソースファイル名(拡張子を含まない) + * @throws IOException + * @throws SQLException + */ + public static void showED01(Connection con, Node node, String iFileName) throws IOException, SQLException { + String idrefStr = ""; + String nameStr = ""; + PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?"); + PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)"); + try { + ArrayList bris = new ArrayList<>(); + NodeList nodes = node.getChildNodes(); + for (int i=0; i < nodes.getLength(); i++) { + Node node2 = nodes.item(i); + switch (node2.getNodeName()) { + case "ksj:POS": + NamedNodeMap nodeMap = node2.getAttributes(); + if (null != nodeMap) { + for ( int j=0; j < nodeMap.getLength(); j++ ) { + if (nodeMap.item(j).getNodeName().equals("idref")) { + idrefStr = nodeMap.item(j).getNodeValue(); + System.out.println("found idref='"+ idrefStr +"'"); + break; + } + } + } break; + case "ksj:BSN": + nameStr = node2.getTextContent(); + break; + case "ksj:BRI": + String[] rtn = anaComm(node2); + if (rtn != null) { + bris.add(rtn); + } break; + default: + break; + } + } + + // idref と nameStr をデータベースに格納する + boolean insert = true; + ps1.setString(1, idrefStr); + try (ResultSet rset = ps1.executeQuery()) { + if (rset.next()) { + insert = false; + } + } + + if (insert) { + ps2.setString(1, idrefStr); + ps2.setString(2, nameStr); + ps2.setString(3, iFileName); + System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')"); + ps2.executeUpdate(); + } + } + finally { + ps1.close(); + ps2.close(); + } + } + + /** * 'table.BUS_STOP'を新規に作る * 既にテーブルが存在する時には何もしない * @param conHsql