巨大森林を分割する
Revisão | c771d838e51acea432e1f5d1f4cd55b061a7a90b (tree) |
---|---|
Hora | 2013-08-03 10:36:43 |
Autor | hayashi.yuu <hayashi.yuu@gmai...> |
Commiter | hayashi.yuu |
テーブルをCREATEする前にテーブルの存在を確認する
@@ -1,4 +1,3 @@ | ||
1 | 1 | #!/bin/sh |
2 | -rm -r database | |
3 | - java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter natural_wood_kanagawa.osm > out.txt | |
2 | + java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter natural_wood_kanagawa.osm | |
4 | 3 | #java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter koubouyama159740689.osm |
\ No newline at end of file |
@@ -2,6 +2,7 @@ package osm.jp; | ||
2 | 2 | |
3 | 3 | import java.io.*; |
4 | 4 | import java.sql.Connection; |
5 | +import java.sql.DatabaseMetaData; | |
5 | 6 | import java.sql.PreparedStatement; |
6 | 7 | import java.sql.ResultSet; |
7 | 8 | import java.sql.SQLException; |
@@ -33,6 +34,8 @@ public class DbBigrelation | ||
33 | 34 | Connection con = null; |
34 | 35 | try { |
35 | 36 | con = DatabaseTool.openDb("database"); |
37 | + DbBigrelation.isTable(con, "NODE"); | |
38 | + DbBigrelation.initDb(con); | |
36 | 39 | DbBigrelation.export(con); |
37 | 40 | } |
38 | 41 | finally { |
@@ -58,10 +61,36 @@ public class DbBigrelation | ||
58 | 61 | * @throws SQLException |
59 | 62 | */ |
60 | 63 | public static void create(Connection con) throws SQLException { |
61 | - create_NODE(con); | |
62 | - create_TAG(con); | |
63 | - create_NDREF(con); | |
64 | - create_MEMBER(con); | |
64 | + if (!isTable(con, "NODE")) { | |
65 | + create_NODE(con); | |
66 | + } | |
67 | + if (!isTable(con, "TAG")) { | |
68 | + create_TAG(con); | |
69 | + } | |
70 | + if (!isTable(con, "NDREF")) { | |
71 | + create_NDREF(con); | |
72 | + } | |
73 | + if (!isTable(con, "MEMBER")) { | |
74 | + create_MEMBER(con); | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * DATABASE.TABLEが存在するかどうか調べる | |
80 | + */ | |
81 | + public static boolean isTable(Connection con, String tableName) throws SQLException { | |
82 | + boolean isTable = false; | |
83 | + DatabaseMetaData dmd = con.getMetaData(); | |
84 | + ResultSet rs = dmd.getTables(null, null, tableName, null); | |
85 | + try { | |
86 | + while (rs.next()) { | |
87 | + isTable = true; | |
88 | + } | |
89 | + } finally { | |
90 | + rs.close(); | |
91 | + } | |
92 | + System.out.println("\tisTable(" + tableName + ")\t"+ Boolean.toString(isTable)); | |
93 | + return isTable; | |
65 | 94 | } |
66 | 95 | |
67 | 96 | /** |