public static Vector<DBColumnModel> getColumnByCode(String tableCode) {

    if (conn == null) conn = DBConnection.getConnection();

    Vector<DBColumnModel> result = new Vector<DBColumnModel>();
    String query = " SELECT * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='" + tableCode + "'";
    Statement stmt;
    try {
      stmt = conn.createStatement();
      stmt.executeQuery(query);
      ResultSet rst = stmt.getResultSet();
      while (rst.next()) {
        DBColumnModel desc = new DBColumnModel();
        desc.setKod(rst.getString(4));
        String isNullable = rst.getString(7);
        if (isNullable.equalsIgnoreCase("YES")) {
          desc.setNullable(true);
        } else {
          desc.setNullable(false);
        }

        desc.setTip(rst.getString(8));
        if (rst.getString(9) != null) {
          desc.setDuzina(new Integer(rst.getString(9)));
        }
        result.add(desc);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return result;
  }
  public static boolean isForeignKey(String tableCode, String columnCode) {
    if (conn == null) conn = DBConnection.getConnection();

    String query = "SELECT * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE;";
    Statement stmt;
    try {
      stmt = conn.createStatement();
      stmt.executeQuery(query);
      ResultSet rst = stmt.getResultSet();
      while (rst.next()) {
        if (rst.getString(6).equalsIgnoreCase(tableCode)
            && rst.getString(7).equalsIgnoreCase(columnCode)
            && rst.getString(3).startsWith("PK")) {
          return true;
        }
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return false;
  }
  public static Vector<String> getTableCodes() {

    Vector<String> ret = new Vector<>();
    String query = "SELECT * from INFORMATION_SCHEMA.TABLES;";
    Statement stmt;

    if (conn == null) conn = DBConnection.getConnection();

    try {
      stmt = conn.createStatement();
      stmt.executeQuery(query);
      ResultSet rst = stmt.getResultSet();
      while (rst.next()) {
        ret.add(rst.getString(3));
      }
      stmt.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    return ret;
  }
  public static HashMap<String, String> getParentCodeAndColumnCodInParent(
      String tableCode, String columnCode) throws SQLException {

    if (conn == null) conn = DBConnection.getConnection();

    if (dbMetadata == null) dbMetadata = conn.getMetaData();

    HashMap<String, String> res = new HashMap<String, String>();
    ResultSet result;
    try {
      result = dbMetadata.getImportedKeys(null, "dbo", tableCode);
      while (result.next()) {
        if (result.getString(8).equals(columnCode)) {
          res.put(
              result.getString(3), result.getString(4)); // 3 - naziv tabele iz koje je nasledjen
        } // 4 - naziv koda u toj tabeli
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return res;
  }
 public DBQueryTable() {
   conn = DBConnection.getConnection();
 }