| |
---|
| | import org.w3c.dom.NodeList; |
---|
| | import org.xml.sax.SAXException; |
---|
| | import osm.jp.api.Db; |
---|
| | |
---|
| | public class DbFuel { |
---|
| | public static final String TABLE_NAME = "FUEL"; |
---|
| | public class DbExist { |
---|
| | public static final String TABLE_NAME = "FUEL_EXIST"; |
---|
| | |
---|
| | /** メイン |
---|
| | * @param args |
---|
| | * @throws IOException |
---|
| |
---|
| | * @throws javax.xml.parsers.ParserConfigurationException |
---|
| | * @throws org.xml.sax.SAXException */ |
---|
| | public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, IOException, SQLException, ParserConfigurationException, SAXException |
---|
| | { |
---|
| | // HSQLディレクトリがなければ作る |
---|
| | File dbdir = new File("database"); |
---|
| | if (!dbdir.isDirectory()) { |
---|
| | dbdir.mkdir(); |
---|
| | } |
---|
| | Connection con = null; |
---|
| | try { |
---|
| | // DB.tableを作成 |
---|
| | con = DatabaseTool.openDb("database"); |
---|
| |
---|
| | inputFile(con, gmlFile, areacode); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | DbFuel.export(con); |
---|
| | DbExist.export(con); |
---|
| | } |
---|
| | finally { |
---|
| | if (con != null) { |
---|
| | DatabaseTool.closeDb(con); |
---|
| |
---|
| | return name.toUpperCase().endsWith(".XML"); |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 'table.FUEL'を新規に作る |
---|
| | * 'table.FUEL_EXIST'を新規に作る |
---|
| | * 既にテーブルが存在する時には何もしない |
---|
| | * @param con |
---|
| | * @throws SQLException |
---|
| | */ |
---|
| | public static void create(Connection con) throws SQLException { |
---|
| | String createSt; |
---|
| | |
---|
| | // 'table.FUEL'を新規に作る |
---|
| | //Db.drop(con, TABLE_NAME); |
---|
| | createSt = "CREATE TABLE "+ TABLE_NAME +" (idref VARCHAR(12) NOT NULL, lat DOUBLE, lon DOUBLE, fixed INT, area INT)"; |
---|
| | // 'table.FUEL_EXIST'を新規に作る |
---|
| | createSt = "CREATE TABLE "+ TABLE_NAME +" (idref VARCHAR(12) NOT NULL, lat DOUBLE, lon DOUBLE, score INT PRIMARY KEY(lat, lon));"; |
---|
| | Db.updateSQL(con, createSt); |
---|
| | |
---|
| | /* |
---|
| | drop(con, "existing_data"); |
---|
| | createSt = "CREATE TABLE existing_data (idref VARCHAR(12) NOT NULL, name VARCHAR(128), lat DOUBLE, lon DOUBLE, score INT, CONSTRAINT existing_pk PRIMARY KEY(idref, lat, lon));"; |
---|
| | Db.updateSQL(con, createSt); |
---|
| | |
---|
| | drop(con, "coverage"); |
---|
| | createSt = "CREATE TABLE coverage (area INT, name VARCHAR(128), denominator BIGINT, lv1 BIGINT, lv2 BIGINT, lv3 BIGINT);"; |
---|
| | Db.updateSQL(con, createSt); |
---|
| | */ |
---|
| |
---|
| | * @param con |
---|
| | * @throws java.sql.SQLException |
---|
| | */ |
---|
| | public static void export(Connection con) throws SQLException { |
---|
| | String header = "idref,lat,lon,fixed"; |
---|
| | String header = "idref,lat,lon,score"; |
---|
| | System.out.println("TABLE: "+ TABLE_NAME); |
---|
| | System.out.println(header); |
---|
| | PreparedStatement ps8 = con.prepareStatement("SELECT idref,lat,lon,fixed,area FROM "+ TABLE_NAME); |
---|
| | PreparedStatement ps8 = con.prepareStatement("SELECT idref,lat,lon,score FROM "+ TABLE_NAME); |
---|
| | try (ResultSet rset8 = ps8.executeQuery()) { |
---|
| | while (rset8.next()) { |
---|
| | String name = rset8.getString(1); |
---|
| | Double lat = rset8.getDouble(2); |
---|
| | Double lon = rset8.getDouble(3); |
---|
| | int fixed = rset8.getInt(4); |
---|
| | int area = rset8.getInt(5); |
---|
| | System.out.println(name +","+ lat +","+ lon +","+ fixed+","+ area); |
---|
| | int score = rset8.getInt(4); |
---|
| | System.out.println(name +","+ lat +","+ lon +","+ score); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |