Esempio n. 1
0
 public boolean dropColumn(String tableName, List<String> drop_column) {
   try {
     StringBuffer sql = new StringBuffer("ALTER TABLE " + tableName);
     for (String column : drop_column) {
       sql.append(" DROP COLUMN " + column + ",");
     }
     jdbcTemplate.execute(sql.substring(0, sql.length() - 1));
     return true;
   } catch (DataAccessException e) {
     WarnLog.logger(e.getMessage());
     return false;
   }
 }
Esempio n. 2
0
 public boolean addColumn(String tableName, Map<String, String> add_column) {
   try {
     StringBuffer sql = new StringBuffer("ALTER TABLE " + tableName);
     for (Iterator<String> it = add_column.keySet().iterator(); it.hasNext(); ) {
       String column = it.next();
       sql.append(" ADD COLUMN " + column + " " + add_column.get(column) + ",");
     }
     jdbcTemplate.execute(sql.substring(0, sql.length() - 1));
     return true;
   } catch (DataAccessException e) {
     WarnLog.logger(e.getMessage());
     return false;
   }
 }
Esempio n. 3
0
 public boolean createTable(String tableName, Map<String, String> column_type) {
   try {
     StringBuffer sql = new StringBuffer("CREATE TABLE " + tableName);
     sql.append("(");
     for (Iterator<String> it = column_type.keySet().iterator(); it.hasNext(); ) {
       String column = it.next();
       sql.append(column + " " + column_type.get(column) + ",");
     }
     jdbcTemplate.execute(sql.substring(0, sql.length() - 1) + ")");
     return true;
   } catch (DataAccessException e) {
     WarnLog.logger(e.getMessage());
     return false;
   }
 }
Esempio n. 4
0
  public Map<String, String> findTable(String tableName) {
    try {
      final Map<String, String> map = new HashMap<String, String>();
      String sql = "DESC " + tableName;
      jdbcTemplate.query(
          sql,
          new RowCallbackHandler() {

            @Override
            public void processRow(ResultSet rs) throws SQLException {
              String key = rs.getString("field");
              String value = rs.getString("type");
              map.put(key, value);
            }
          });
      return map;
    } catch (DataAccessException e) {
      WarnLog.logger(e.getMessage());
      return null;
    }
  }