Newer
Older
osmCoverage / src / osm / jp / api / DbCommand.java
@haya4 haya4 on 7 Apr 2019 770 bytes fixed: DbPostoffice.class
package osm.jp.api;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class DbCommand {
    Connection hsqldb;
    String tableName;
    boolean verbose;
    
    public DbCommand(Connection hsqldb, String tableName) {
        this.hsqldb = hsqldb;
        this.tableName = tableName;
        this.verbose = false;
    }
    
    public DbCommand setVerbose(boolean verbose) {
        this.verbose = verbose;
        return this;
    }
    
    public DbCommand dropTable() throws Exception {
        String sqlStr = "DROP TABLE IF EXISTS "+ tableName;
        try (PreparedStatement ps = hsqldb.prepareStatement(sqlStr)) {
            if (verbose) System.out.println(sqlStr);
            ps.executeUpdate();
        }
        return this;
    }
}