Newer
Older
osmCoverage / src / osm / jp / api / Osmdb.java
  1. package osm.jp.api;
  2.  
  3. import hayashi.yuu.tools.json.JsonTool;
  4. import java.io.*;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.SQLIntegrityConstraintViolationException;
  10. import java.sql.SQLSyntaxErrorException;
  11. import javax.json.Json;
  12. import javax.json.JsonArray;
  13. import javax.json.JsonBuilderFactory;
  14. import javax.json.JsonObject;
  15. import javax.json.JsonObjectBuilder;
  16. import javax.json.JsonValue;
  17. import javax.xml.parsers.ParserConfigurationException;
  18. import jp.co.areaweb.tools.csv.CsvRecord;
  19. import jp.co.areaweb.tools.database.DatabaseTool;
  20. import org.hsqldb.HsqlException;
  21. import org.w3c.dom.NamedNodeMap;
  22. import org.w3c.dom.Node;
  23. import org.w3c.dom.NodeList;
  24. import org.xml.sax.SAXException;
  25.  
  26. public abstract class Osmdb {
  27.  
  28. public String tableName;
  29. public Connection hsqldb = null; // hsqldb DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB);
  30. public Osmdb(Connection hsqldb, String tableName) {
  31. this.hsqldb = hsqldb;
  32. this.tableName = tableName;
  33. }
  34.  
  35. abstract public void create() throws SQLException;
  36. void sql(String sql) throws SQLException {
  37. System.out.println(sql);
  38. try (PreparedStatement ps = hsqldb.prepareStatement(sql)) {
  39. ps.executeUpdate();
  40. }
  41. catch (SQLSyntaxErrorException e) {
  42. System.out.println("107:"+ e.toString());
  43. if (!(e.toString().startsWith("java.sql.SQLSyntaxErrorException: user lacks privilege or object not found:"))) {
  44. throw e;
  45. }
  46. }
  47. }
  48.  
  49. public static void outputWriter(PrintWriter pw, String text) {
  50. System.out.println("\t" + text);
  51. pw.print(text);
  52. }
  53. public static final int POINT_NO = 0; // 評価ポイント無し→ score=50
  54. public static final int POINT_FIXME = 1; // 評価ポイント|!(fixme=null) → score=1
  55. public static final int POINT_NO_BRAND = 2; // 評価ポイント|brand=null → score=1
  56. public static final int POINT_NO_NAME = 4; // 評価ポイント|name=null → score=1
  57. public static final int POINT_BUS_NO = 8; // 評価ポイント|!(bus=yes) → score=0
  58. /**
  59. * 'table.OSM_EXIST'の内容をCSV形式にして標準出力に出力する
  60. * @throws java.sql.SQLException
  61. */
  62. public void export() throws SQLException {
  63. String header = "idref,lat,lon,score";
  64. System.out.println("TABLE: "+ tableName);
  65. System.out.println(header);
  66. PreparedStatement ps8 = hsqldb.prepareStatement(
  67. "SELECT idref,lat,lon,score,removed FROM "+ tableName
  68. );
  69. try (ResultSet rset8 = ps8.executeQuery()) {
  70. while (rset8.next()) {
  71. String idcode = rset8.getString(1);
  72. Double lat = rset8.getDouble(2);
  73. Double lon = rset8.getDouble(3);
  74. int score = rset8.getInt(4);
  75. boolean removed = rset8.getBoolean(5);
  76. String out = String.format(
  77. "OSM: %s,%2.5f,%3.5f,%d,%b",
  78. idcode, lat, lon, score, removed
  79. );
  80. System.out.println(out);
  81. }
  82. }
  83. }
  84.  
  85. public int importExistingNode(Connection osmdb, ResultSet rset, int point, boolean removed) throws IOException, SQLException {
  86. String osmidStr = rset.getString("osm_id");
  87. String latStr = rset.getString("lat");
  88. String lonStr = rset.getString("lon");
  89. String brandStr = rset.getString("brand");
  90. String nameStr = rset.getString("name");
  91. String fixmeStr = "";
  92.  
  93. int score = 50;
  94. if (((point & POINT_NO_BRAND) != 0) && isNull(brandStr)) {
  95. score = 1;
  96. }
  97. if (((point & POINT_NO_NAME) != 0) && isNull(nameStr)) {
  98. score = 1;
  99. }
  100. boolean fixme = false;
  101. boolean busYes = false;
  102. if (((point & (POINT_FIXME | POINT_BUS_NO)) != 0)) {
  103. PreparedStatement ps8 = osmdb.prepareStatement(
  104. "SELECT * FROM planet_osm_nodes where id='"+ osmidStr +"'"
  105. );
  106. try (ResultSet rset8 = ps8.executeQuery()) {
  107. while (rset8.next()) {
  108. String tags = rset8.getString("tags");
  109. if (tags != null) {
  110. tags = tags.substring(1);
  111. tags = tags.substring(0, tags.length()-1);
  112. CsvRecord csv = new CsvRecord();
  113. csv.analizeRecord(tags);
  114. boolean key = true;
  115. boolean bus = false;
  116. for (String str : csv) {
  117. if (key) {
  118. if (str.startsWith("fixme")) {
  119. fixme = true;
  120. }
  121. if (str.equals("bus")) {
  122. bus = true;
  123. }
  124. key = false;
  125. }
  126. else {
  127. if (bus) {
  128. if (str.equals("yes")) {
  129. busYes = true;
  130. }
  131. bus = false;
  132. }
  133. key = true;
  134. }
  135. }
  136. //System.out.println(tags);
  137. }
  138. }
  139. }
  140. if (((point & POINT_FIXME) != 0) && fixme) {
  141. score = 1;
  142. }
  143. if (((point & POINT_BUS_NO) != 0) && !busYes) {
  144. score = 1;
  145. }
  146. }
  147. if (score > 0) {
  148. // idref と brandStr をデータベースに格納する
  149. System.out.println(
  150. "INSERT INTO "+ tableName
  151. + " (idref,lat,lon,score,name,removed) VALUES ("
  152. + osmidStr +","
  153. + latStr +","
  154. + lonStr +","
  155. + Integer.toString(score) +","
  156. + "'"+ nameStr +"',"
  157. + "false"
  158. + ")N"
  159. );
  160. try (PreparedStatement ps5 = hsqldb.prepareStatement(
  161. "INSERT INTO "+ tableName +" (idref,lat,lon,score,name,removed) VALUES (?,?,?,?,?,?)"
  162. )) {
  163. ps5.setString(1, osmidStr);
  164. ps5.setDouble(2, Double.parseDouble(latStr));
  165. ps5.setDouble(3, Double.parseDouble(lonStr));
  166. ps5.setInt(4, score);
  167. ps5.setString(5, nameStr);
  168. ps5.setBoolean(6, removed);
  169. ps5.executeUpdate();
  170. return 1;
  171. }
  172. catch (HsqlException | SQLIntegrityConstraintViolationException e) {
  173. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  174. // [HsqlException]は、無視する
  175. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  176. // [SQLIntegrityConstraintViolationException]は、無視する
  177. }
  178. }
  179.  
  180. return 0;
  181. }
  182.  
  183. /**
  184. * File(HttpPOST.EXIST_FILE)を読み取って、データベースに反映させる。<br>
  185. * その際に、OSMノードを評価し、scoreを算定する
  186. *
  187. * @param sqlWhere POI条件
  188. * @param point 評価ポイント[POINT_NO|POINT_BRAND|POINT_NAME] 1: 'brand' 2:'name'
  189. * @param removed
  190. * @throws Exception エラー
  191. */
  192. public void readExisting(String sqlWhere, int point, boolean removed) throws Exception {
  193. long counter = 0L;
  194. try (Connection osmdb = DatabaseTool.openDb("osmdb")) {
  195. String sqlSelect = "osm_id,"
  196. + "brand,"
  197. + "disused,"
  198. + "name,"
  199. + "ST_Y(ST_Transform(way,4326)) as lat,"
  200. + "ST_X(ST_Transform(way,4326)) as lon";
  201. String sqlNode = String.format(
  202. "SELECT %s FROM planet_osm_point %s",
  203. sqlSelect,
  204. sqlWhere
  205. );
  206. PreparedStatement ps1 = osmdb.prepareStatement(sqlNode);
  207. try (ResultSet rset1 = ps1.executeQuery()) {
  208. while (rset1.next()) {
  209. counter += importExistingNode(osmdb, rset1, point, removed);
  210. }
  211. }
  212. String sqlArea = String.format(
  213. "SELECT %s FROM planet_osm_polygon %s",
  214. "osm_id,brand,disused,name,ST_Y(ST_Transform(ST_Centroid(way),4326)) as lat,ST_X(ST_Transform(ST_Centroid(way),4326)) as lon",
  215. sqlWhere
  216. );
  217. PreparedStatement ps2 = osmdb.prepareStatement(sqlArea);
  218. try (ResultSet rset2 = ps2.executeQuery()) {
  219. while (rset2.next()) {
  220. counter += importExistingNode(osmdb, rset2, point, removed);
  221. }
  222. }
  223.  
  224. System.out.println("Exists Node count = " + counter);
  225. }
  226. }
  227.  
  228. /**
  229. *
  230. * SELECT
  231. * planet_osm_nodes.id,
  232. * planet_osm_nodes.tags
  233. * planet_osm_nodes.way --> lat & lon
  234. * FROM
  235. * public.planet_osm_point,
  236. * public.planet_osm_nodes
  237. * WHERE (
  238. * planet_osm_point.osm_id = planet_osm_nodes.id
  239. * and 'disused:amenity'=ANY(planet_osm_nodes.tags)
  240. * and 'fuel'=ANY(planet_osm_nodes.tags)
  241. * )
  242. *
  243. * @param kStr
  244. * @param vStr
  245. * @param point
  246. * @throws Exception
  247. */
  248. public void readExistingSub(String kStr, String vStr, int point) throws Exception {
  249. readExistingSub(kStr, vStr, point, true);
  250. }
  251. public void readExistingSub(String kStr, String vStr, int point, boolean removed) throws Exception {
  252. JsonBuilderFactory factory = Json.createBuilderFactory(null);
  253. JsonObjectBuilder builder = factory.createObjectBuilder();
  254. builder.add("k",kStr);
  255. builder.add("v", vStr);
  256. JsonObject tag = builder.build();
  257. readExistingSub(tag, point, removed);
  258. }
  259. /**
  260. *
  261. * @param tag {k: string, v: string}
  262. * @param point
  263. * @throws Exception
  264. */
  265. public void readExistingSub(JsonObject tag,int point) throws Exception {
  266. readExistingSub(tag, point, true);
  267. }
  268.  
  269. /**
  270. *
  271. * @param tag {k: string, v: string}
  272. * @param point
  273. * @param removed
  274. * @throws Exception
  275. */
  276. public void readExistingSub(JsonObject tag,int point, boolean removed) throws Exception {
  277. long counter = 0L;
  278. try (Connection osmdb = DatabaseTool.openDb("osmdb")) {
  279. String sqlSelect = "SELECT tags,id,ST_Y(ST_Transform(way,4326)) as lat,ST_X(ST_Transform(way,4326)) as lon";
  280. String sqlWhere = String.format(
  281. "WHERE (osm_id=id AND '%s'=ANY(tags) AND '%s'=ANY(tags))",
  282. tag.getString("k"), tag.getString("v")
  283. );
  284. String sql = String.format(
  285. "%s FROM planet_osm_point,planet_osm_nodes %s", sqlSelect, sqlWhere
  286. );
  287. System.out.println(sql);
  288. PreparedStatement ps1 = osmdb.prepareStatement(sql);
  289. try (ResultSet rset1 = ps1.executeQuery()) {
  290. while (rset1.next()) {
  291. String tags = rset1.getString("tags");
  292. String idref = rset1.getString("id");
  293. String latStr = rset1.getString("lat");
  294. String lonStr = rset1.getString("lon");
  295. double lat = Double.valueOf(latStr);
  296. double lon = Double.valueOf(lonStr);
  297. int score = score(point, tags);
  298. counter += insertExistingNode(idref, lat, lon, score, "", removed);
  299. }
  300. }
  301. System.out.println("Exists Node count = " + counter);
  302. }
  303. }
  304.  
  305. /**
  306. *
  307. * @param array tags: [{k: string, v: string}]
  308. * @param point
  309. * @throws Exception
  310. */
  311. public void readExistingSub(JsonArray array,int point) throws Exception {
  312. readExistingSub(array,point, true);
  313. }
  314.  
  315. /**
  316. *
  317. * @param array tags: [{k: string, v: string}]
  318. * @param point
  319. * @param removed
  320. * @throws Exception
  321. */
  322. public void readExistingSub(JsonArray array,int point, boolean removed) throws Exception {
  323. long counter = 0L;
  324. try (Connection osmdb = DatabaseTool.openDb("osmdb")) {
  325. String sqlSelect = "SELECT "
  326. + "tags,"
  327. + "id,"
  328. + "ST_Y(ST_Transform(way,4326)) as lat,"
  329. + "ST_X(ST_Transform(way,4326)) as lon";
  330. String sqlSS = "";
  331. for (JsonValue v : array) {
  332. JsonObject tag = (JsonObject)v;
  333. sqlSS += String.format(
  334. " AND ('%s'=ANY(tags) AND '%s'=ANY(tags))",
  335. tag.getString("k"), tag.getString("v")
  336. );
  337. }
  338. String sqlWhere = String.format("WHERE (osm_id=id %s)", sqlSS);
  339. String sql = String.format(
  340. "%s FROM planet_osm_point,planet_osm_nodes %s",
  341. sqlSelect, sqlWhere
  342. );
  343. System.out.println(sql);
  344. PreparedStatement ps1 = osmdb.prepareStatement(sql);
  345. try (ResultSet rset1 = ps1.executeQuery()) {
  346. while (rset1.next()) {
  347. String tags = rset1.getString("tags");
  348. String idref = rset1.getString("id");
  349. String latStr = rset1.getString("lat");
  350. String lonStr = rset1.getString("lon");
  351. double lat = Double.valueOf(latStr);
  352. double lon = Double.valueOf(lonStr);
  353. int score = score(point, tags);
  354. counter += insertExistingNode(idref, lat, lon, score, "", removed);
  355. }
  356. }
  357. System.out.println("Exists Node count = " + counter);
  358. }
  359. }
  360.  
  361. int score(int point, String tags) {
  362. int score = 50;
  363. if (tags == null) {
  364. return score;
  365. }
  366. boolean brandYes = false;
  367. boolean busYes = false;
  368. boolean fixmeYes = false;
  369. boolean nameYes = false;
  370. tags = tags.substring(1);
  371. tags = tags.substring(0, tags.length()-1);
  372. CsvRecord csv = new CsvRecord();
  373. csv.analizeRecord(tags);
  374.  
  375. boolean key = true;
  376. boolean bus = false;
  377. for (String str : csv) {
  378. if (key) {
  379. if (str.startsWith("fixme")) {
  380. fixmeYes = true;
  381. }
  382. else if (str.equals("bus")) {
  383. bus = true;
  384. }
  385. else if (str.equals("brand")) {
  386. brandYes = true;
  387. }
  388. else if (str.startsWith("name")) {
  389. nameYes = true;
  390. }
  391. key = false;
  392. }
  393. else {
  394. if (bus) {
  395. if (str.equals("yes")) {
  396. busYes = true;
  397. }
  398. bus = false;
  399. }
  400. key = true;
  401. }
  402. }
  403. if (((point & POINT_NO_BRAND) != 0) && !brandYes) {
  404. score = 1;
  405. }
  406. if (((point & POINT_NO_NAME) != 0) && !nameYes) {
  407. score = 1;
  408. }
  409. if (((point & POINT_FIXME) != 0) && fixmeYes) {
  410. score = 1;
  411. }
  412. if (((point & POINT_BUS_NO) != 0) && !busYes) {
  413. score = 1;
  414. }
  415. return score;
  416. }
  417. /**
  418. *
  419. * @param idref
  420. * @param lat
  421. * @param lon
  422. * @param score
  423. * @param name
  424. * @return
  425. * @throws IOException
  426. * @throws SQLException
  427. */
  428. public int insertExistingNode(String idref, double lat, double lon, int score, String name) throws IOException, SQLException {
  429. return insertExistingNode(idref, lat, lon, score, name, false);
  430. }
  431.  
  432. /**
  433. *
  434. * @param idref
  435. * @param lat
  436. * @param lon
  437. * @param score
  438. * @param name
  439. * @param removed
  440. * @return
  441. * @throws IOException
  442. * @throws SQLException
  443. */
  444. public int insertExistingNode(String idref, double lat, double lon, int score, String name, boolean removed) throws IOException, SQLException {
  445. // idref と brandStr をデータベースに格納する
  446. /*
  447. */
  448. String sql = String.format("DELETE FROM %s WHERE idref=?", tableName);
  449. try (PreparedStatement ps5 = hsqldb.prepareStatement(sql)) {
  450. ps5.setString(1, idref);
  451. ps5.executeUpdate();
  452. }
  453. catch (HsqlException | SQLIntegrityConstraintViolationException e) {
  454. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  455. // [HsqlException]は、無視する
  456. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  457. // [SQLIntegrityConstraintViolationException]は、無視する
  458. }
  459.  
  460. sql = String.format(
  461. "INSERT INTO %s (idref,lat,lon,score,name,removed) VALUES (%s,%2.7f,%3.7f,%d,%s,%s)",
  462. tableName,
  463. idref, lat, lon, score, name, (removed ? "true":"false")
  464. );
  465. System.out.println(sql);
  466. sql = String.format(
  467. "INSERT INTO %s (idref,lat,lon,score,name,removed) VALUES (?,?,?,?,?,?)",
  468. tableName
  469. );
  470. try (PreparedStatement ps5 = hsqldb.prepareStatement(sql)) {
  471. ps5.setString(1, idref);
  472. ps5.setDouble(2, lat);
  473. ps5.setDouble(3, lon);
  474. ps5.setInt(4, score);
  475. ps5.setString(5, name);
  476. ps5.setBoolean(6, removed);
  477. ps5.executeUpdate();
  478. return 1;
  479. }
  480. catch (HsqlException | SQLIntegrityConstraintViolationException e) {
  481. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  482. // [HsqlException]は、無視する
  483. // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
  484. // [SQLIntegrityConstraintViolationException]は、無視する
  485. }
  486. return 0;
  487. }
  488. /**
  489. * REMOVEDファイルからデータを揉み込む
  490. *
  491. * @param revovedFile
  492. * @throws FileNotFoundException
  493. * @throws IOException
  494. * @throws SQLException
  495. */
  496. public void loadRemoved(File revovedFile) throws FileNotFoundException, IOException, SQLException {
  497. if (revovedFile == null) {
  498. throw new FileNotFoundException();
  499. }
  500. if (!revovedFile.exists()) {
  501. throw new FileNotFoundException();
  502. }
  503. if (!revovedFile.isFile()) {
  504. throw new FileNotFoundException();
  505. }
  506. try (PreparedStatement ps = hsqldb.prepareStatement(
  507. "UPDATE "
  508. + tableName
  509. + " SET idref=?,removed=true,fixed1=100"
  510. + " WHERE gmlid=? AND area=?"
  511. )) {
  512. LineNumberReader reader = new LineNumberReader(
  513. new InputStreamReader(new FileInputStream(revovedFile))
  514. );
  515. String lineStr;
  516. while ((lineStr = reader.readLine()) != null) {
  517. if (lineStr == null) {
  518. continue;
  519. }
  520. if (lineStr.trim().length() < 3) {
  521. continue;
  522. }
  523.  
  524. JsonObject json = JsonTool.parse(lineStr);
  525. String gmlid = json.getString("gmlid");
  526. String idref = json.getString("idref");
  527. int area = json.getInt("area");
  528.  
  529. ps.setString(1, idref);
  530. ps.setString(2, gmlid);
  531. ps.setInt(3, area);
  532. ps.executeUpdate();
  533. }
  534. }
  535. }
  536. /**
  537. * removedデータをファイルに出力する
  538. *
  539. * @param removedFile
  540. * @throws SQLException
  541. * @throws java.io.IOException
  542. */
  543. public void outputRemoved(File removedFile) throws SQLException, IOException {
  544. String whereStr = "WHERE (removed=?)";
  545. String fromStr = "FROM "+ tableName;
  546. String sortStr = "ORDER BY area,gmlid";
  547. String sql = String.format("SELECT * %s %s %s", fromStr, whereStr, sortStr);
  548. try (FileWriter fw = new FileWriter(removedFile);
  549. PreparedStatement ps1 = hsqldb.prepareStatement(sql))
  550. {
  551. System.out.println(sql);
  552. ps1.setBoolean(1, true);
  553. try (ResultSet rset1 = ps1.executeQuery()) {
  554. while (rset1.next()) {
  555. String gmlid = rset1.getString("gmlid");
  556. int area = rset1.getInt("area");
  557. String idref = rset1.getString("idref");
  558. JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
  559. jsonBuilder.add("gmlid", gmlid);
  560. jsonBuilder.add("idref", (idref==null ? "" : idref));
  561. jsonBuilder.add("area", area);
  562. JsonObject value = jsonBuilder.build();
  563. String line = value.toString();
  564. fw.write(line);
  565. fw.write("\n");
  566. fw.flush();
  567. }
  568. }
  569. fw.close();
  570. }
  571. }
  572.  
  573. boolean isNull(String vstr) {
  574. if (vstr == null) {
  575. return true;
  576. }
  577. return (vstr.trim().length() < 1);
  578. }
  579.  
  580. int readAreaNodes(Connection con, Node node) throws IOException, SQLException {
  581. int iCounter = 0;
  582.  
  583. NodeList nodes = node.getChildNodes();
  584. for (int i = 0; i < nodes.getLength(); i++) {
  585. Node node2 = nodes.item(i);
  586. switch (node2.getNodeName()) {
  587. case "node":
  588. iCounter++;
  589. importAreaNode(con, node2);
  590. break;
  591. default:
  592. iCounter += readAreaNodes(con, node2);
  593. break;
  594. }
  595. }
  596. return iCounter;
  597. }
  598.  
  599. void importAreaNode(Connection con, Node node) throws IOException, SQLException {
  600. String idrefStr = "";
  601. String latStr = "";
  602. String lonStr = "";
  603.  
  604. NodeList nodes = node.getChildNodes();
  605. if (nodes.getLength() > 0) {
  606. return;
  607. }
  608.  
  609. NamedNodeMap nodeMap = node.getAttributes();
  610. if (nodeMap != null) {
  611. for (int j=0; j < nodeMap.getLength(); j++) {
  612. switch (nodeMap.item(j).getNodeName()) {
  613. case "id":
  614. idrefStr = nodeMap.item(j).getNodeValue();
  615. break;
  616. case "lat":
  617. latStr = nodeMap.item(j).getNodeValue();
  618. break;
  619. case "lon":
  620. lonStr = nodeMap.item(j).getNodeValue();
  621. break;
  622. default:
  623. break;
  624. }
  625. }
  626. // idref と brandStr をデータベースに格納する
  627. System.out.println("insert into AREA_NODE(idref,lat,lon) values("+ idrefStr +","+ latStr +","+ lonStr+")");
  628. try (PreparedStatement ps5 = con.prepareStatement(
  629. "INSERT INTO AREA_NODE (idref,lat,lon) VALUES (?,?,?)"
  630. )) {
  631. ps5.setString(1, idrefStr);
  632. ps5.setDouble(2, Double.parseDouble(latStr));
  633. ps5.setDouble(3, Double.parseDouble(lonStr));
  634. ps5.executeUpdate();
  635. }
  636. }
  637. }
  638. static Position getNdPosition(Connection con, String idref) throws SQLException {
  639. PreparedStatement ps8 = con.prepareStatement(
  640. "SELECT lat,lon FROM AREA_NODE where idref=?"
  641. );
  642. ps8.setString(1, idref);
  643. try (ResultSet rset8 = ps8.executeQuery()) {
  644. while (rset8.next()) {
  645. Double lat = rset8.getDouble(1);
  646. Double lon = rset8.getDouble(2);
  647. return new Position(lat,lon);
  648. }
  649. }
  650. return null;
  651. }
  652. public void dropTable () throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
  653. String sqlStr = "DROP TABLE IF EXISTS "+ tableName;
  654. try (PreparedStatement ps = hsqldb.prepareStatement(sqlStr)) {
  655. System.out.println(sqlStr);
  656. ps.executeUpdate();
  657. }
  658. }
  659. }