title: Displaying MySQL datetime in JTable
body: <p>In a MySQL db I have ta table which contains a datetime column, which has the format '2012-01-18 09:45:30'. I query the contents of this table using the following syntax:</p>
  
  <pre><code>Statement s = conn.createStatement();
  s.executeQuery( "select * from db_name.tbl_name;");
  ResultSet rs = s.getResultSet();
  ResultSetMetaData = rs.getMetaData();
  int numberOfColumns = metaData.getColumnCount();
  
  //Put Column Header info in Vector
  Vector columnNames = new Vector();
  for (int column = 0; column &lt; numberOfColumns; column++) {
      columnNames.addElement(metaData.getColumnLabel(column+1));
  }
  
  //Put sql table data in Vector of Vectors
  Vector data = new Vector();
  while (rs.next()) {
      Vector newRow = new Vector();
      newRow.addElement(rs.getObject(i));
  }
  s.close();
  rs.close();
  DefaultTableModel model = new DefaultTableModel(data,columnNames);
  JTable table = new JTable(model);
  JScrollPane pane = new JScrollPane(table);
  </code></pre>
  
  <p>If I do not override the getColumnClass in the DefaultTableModel then the MySQL datetime column displays in the JTable as a String in the following format: </p>
  
  <pre><code>2012-01-18 09:45:30
  </code></pre>
  
  <p>If I get the class name for the datetime column using the following syntax, the class returned is java.sql.Timestamp</p>
  
  <pre><code>System.out.println(metaData.getColumnClassName(i));
  </code></pre>
  
  <p>Now, this is the part that confuses me. If I override the getColumnClass method in DefaultTableModel to return the correct class, using the following syntax, then the datetime column is formatted and displayed like this:</p>
  
  <pre><code>Jan 18,2012
  </code></pre>
  
  <p>Notice that the time portion is completely omitted. </p>
  
  <pre><code>@override
  public Class getColumnClass(int column) {
      for (int row = 0; row &lt; getRowCount(); row++) {
          Object o = getValueAt(row, column);
          if (o != null) {
              try {
                  switch (metaData.getColumnClassName(column+1)) {
                      case "java.sql.Timestamp":
                          return java.sql.Timestamp.class;
                      case "java.sql.Date":
                          return java.sql.Date.class;
                  } 
              }
              catch (SQLException ex) {
                  Logger.getLogger(ResultSetToCheckBoxTable.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      return Object.class;
  }
  </code></pre>
  
  <p>Also, if I try to display a java.sql.Date column, it displays as a String with the following format: </p>
  
  <pre><code>2012-01-18
  </code></pre>
  
  <p>regardless of whether I override GetColumnClass to return the correct class.</p>
  
  <p>How to display <code>java.sql.Date</code> as: <code>Jan 18, 2012</code> and <code>java.sql.TimeStamp</code> so that it displays the date and time?</p>