Newer
Older
osmCoverage / src / osm / jp / api / Db.java
@yuuhayashi yuuhayashi on 4 Sep 2017 1 KB fuel: table.FUEL の作成
  1. package osm.jp.api;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.SQLException;
  6. import java.sql.SQLSyntaxErrorException;
  7.  
  8. public class Db {
  9. /**
  10. * データを受信しないSQLを実行するに作る
  11. * 既にテーブルが存在する時には何もしない
  12. * @param con
  13. * @param createsql
  14. * @throws SQLException
  15. * @throws java.sql.SQLSyntaxErrorException
  16. */
  17. public static void updateSQL(Connection con, String createsql) throws SQLException, SQLSyntaxErrorException {
  18. System.out.println(createsql);
  19. try (PreparedStatement ps = con.prepareStatement(createsql)) {
  20. ps.executeUpdate();
  21. }
  22. }
  23.  
  24. /**
  25. * 'table.?'を削除するS
  26. * @param con
  27. * @param tableName
  28. * @throws SQLException
  29. */
  30. public static void drop(Connection con, String tableName) throws SQLException {
  31. String createSt = "DROP TABLE "+ tableName +";";
  32. System.out.println(createSt);
  33. try (PreparedStatement ps = con.prepareStatement(createSt)) {
  34. ps.executeUpdate();
  35. }
  36. }
  37. /**
  38. * 'table.FUEL'の内容を空にする
  39. * @param con
  40. * @param tableName
  41. * @throws SQLException
  42. */
  43. public static void clear(Connection con, String tableName) throws SQLException {
  44. String createSt = "DELETE FROM "+ tableName +";";
  45. System.out.println(createSt);
  46. try (PreparedStatement ps = con.prepareStatement(createSt)) {
  47. ps.executeUpdate();
  48. }
  49. }
  50. }