2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2020

11/19/2001: Unspsc Codes Are Four Sets Of Two

UNSPSC codes are four sets of two characters.

Each pair of character helps to define a category in a hierarchical manner. So the left pairs (like 10 00 00 00) define a very broad category while the right pairs (like 11 23 44 02) defines a very narrow category. Giving any category code, you can find its parent category code via the following java code:

// Move the unspsc code into a stringbuffer so it can be manipulated
StringBuffer uc = new StringBuffer(unspsc_code);

// replace digits 7 & 8 with zeros.
// if code has changed then that's the parent category
// The setCharAt function uses a zero-based index.So the
// range is 0 to 7 instead of 1 to 8.
uc.setCharAt(7, '0');
uc.setCharAt(6, '0');

if (! unspsc_code.equals(uc.toString())) {
  System.out.println(uc + " is the parent category");
}
else {
  // replace digits 5 & 6 with zeros.
  uc.setCharAt(5, '0');
  uc.setCharAt(4, '0');
  if (! unspsc_code.equals(uc.toString())) {
    System.out.println(uc + " is the parent category");
  }
  else {
    // replace digits 3 & 4 with zeros.
    uc.setCharAt(3, '0');
    uc.setCharAt(2, '0');
    if (! unspsc_code.equals(uc.toString())) {
      System.out.println(uc + " is the parent category");
    }
    else {
      System.out.println(uc + " is a top-level category.");
    }
  }
}

11/16/2001: Java JDBC Metadata Holds Query Column Names

Java JDBC code to find column names in a query.

  private Connection mAccess;
  private Statement mStatement;
  private ResultSet mResultSet;
  private ResultSetMetaData mResultSetMetaData;

  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  mAccess = DriverManager.getConnection("jdbc:odbc:pma_boeing");

  mStatement = mAccess.createStatement();
  ResultSet mResultSet = mStatement.executeQuery("Select top 10 * from boeing");

  mResultSetMetaData = mResultSet.getMetaData();
  int TotalColumn = mResultSetMetaData.getColumnCount();

  for (int j = 1; j <= TotalColumn; j++) {
    System.out.println("[" + j + "] " + mResultSetMetaData.getColumnName(j));
  }