ResultSet change date

hello,

I have been able to change string values in a ResultSet to automatically update the MySQL db, but I cannot change a date field. The date field does not seem editable, how is this implemented correctly I was trying to use this but to no joy

 public void setValueAt(Object value, int row, int col)
  {

    try
    {
    int tempCol = col ;
    tempCol ++ ;
    if((tempCol == 4) || (tempCol == 5))
    {
      rs.updateString (tempCol, String.valueOf (value)) ;
    }
    else
      rs.updateDate (tempCol, Date.valueOf (String.valueOf(value))) ;
   
      rs.updateRow(  );

    }
    catch (SQLException s)
    {
      s.printStackTrace();
    }
  }
CyartAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
What is 'value' when it contains a date?
0
objectsCommented:
If you date string is not in the expected format then you will need to use SimpleDateFormat to  parse it.

http://javaalmanac.com/egs/java.text/ParseDate.html
0
CyartAuthor Commented:
Hello,

The object that is passed back is a java.sql.Date object, but when it is displayed in the Jtable it appears as dd-mmm-yyyy, so there is some sort of conversion going on behind the scenes. If Cast to char in the java sql statement it brings it back as yyyy-mm-dd, but I recieve resultset is not editable error.

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

CEHJCommented:
Have you written a custom TableModel?
0
CyartAuthor Commented:

Please find attached the two classes I am using its the editableResults class that is giving me the date trouble




class DBResultSet extends AbstractTableModel
{
  protected ResultSet rs  ;
  DBConnection rsConnection;
  protected ResultSetMetaData meta;
  protected int rowCount;
  boolean closing = false;


//close the database connection
  void closeConnection ()
  {
    closing = true;
    try
    {
      if (!rsConnection.conn.isClosed ())
      {
        rsConnection.closeConnection () ;
      }
    }
    catch(SQLException e)
    {
      e.printStackTrace();
    }
  }


  public DBResultSet(String query)
  {
    rsConnection = new DBConnection();
//Execute the database query (connection is opened during DBConnection.getquery)
    getQuery(query);
  }

//required for extending abstractTableModel
  //get the number of columns in the resultset
  public int getColumnCount() throws IllegalStateException
  {
    try
    {
      if (!rsConnection.conn.isClosed ())
      {
        return meta.getColumnCount () ;
      }
      else
        {
          JOptionPane.showMessageDialog(null, "The database connection has been"
              + "closed unexpectedly.",
              "Database Connection Closed", JOptionPane.ERROR_MESSAGE);
        return -1;
        }

    }
    catch(SQLException e)
    {
      e.printStackTrace();
    }
    catch (NullPointerException n)
    {

    }
    return 0;
  }

//required for extending abstractTableModel
  //get the number of rows in the resultset
  public int getRowCount() throws IllegalStateException
  {
    if (!closing)
    {
      try
      {
        if (!rsConnection.conn.isClosed ())
        {
          return rowCount ;
        }
        else
        {
          JOptionPane.showMessageDialog(null, "The database connection has been"
              + "closed unexpectedly.",
              "Database Connection Closed", JOptionPane.ERROR_MESSAGE);
          return -1;
        }
      }
      catch (SQLException e)
      {
        e.printStackTrace () ;
      }
      catch (NullPointerException n)
      {
        return -1;
      }
    }
    return 0;
  }


//required for extending abstractTableModel
//get the value of a specific cell in the resultset
  public Object getValueAt(int row, int column)
      throws IllegalStateException
  {
    try
    {
      if (!rsConnection.conn.isClosed())
      {
        rs.absolute (row + 1) ;
        return rs.getObject (column + 1) ;
      }
      else
        {
          JOptionPane.showMessageDialog(null, "The database connection has been"
              + "closed unexpectedly.",
              "Database Connection Closed", JOptionPane.ERROR_MESSAGE);
        }

    }
    catch(SQLException e)
    {
        e.printStackTrace();
    }
    return "error";
  }

//execute the database query
  protected void getQuery (String query)
  {
    try
    {

      rs = rsConnection.getQuery(query);//create connection in dbconnection.getQuery
      if(!rsConnection.conn.isClosed())
      {
        meta = rs.getMetaData () ;
        System.out.println(meta) ;
        rs.last () ;
        rowCount = rs.getRow () ;
      }
    }
    catch (SQLException e)
    {
      // Could not connect to the database
      /*JOptionPane.showMessageDialog(null, "The database connection attempt "
                              + "was unsuccessful.",
                              "Database Connection Closed",
                              JOptionPane.ERROR_MESSAGE);*/
      System.out.println(e.getMessage());
    }
    catch (NullPointerException n)
    {
    /*JOptionPane.showMessageDialog(null, "The database connection attempt "
                                  + "was unsuccessful.",
                                  "Database Connection Closed",
                                  JOptionPane.ERROR_MESSAGE);*/
    System.out.println(n.getMessage());
  }
  }

//get the name of the selected column
  public String getColumnName(int column) throws IllegalStateException{
  try
    {
      if(!rsConnection.conn.isClosed())
      {
      return meta.getColumnName(column + 1);
      }
      else
        {
          JOptionPane.showMessageDialog(null, "The database connection has been"
              + "closed unexpectedly.",
              "Database Connection Closed", JOptionPane.ERROR_MESSAGE);
        }
    }
    catch(SQLException sqlException)
    {
      sqlException.printStackTrace();
    }
    return null;
  }

//get the column data type
  public Class getColumnClass(int column) throws IllegalStateException
  {
    try
    {
      if (!rsConnection.conn.isClosed ())
      {
        String classname = meta.getColumnClassName (column + 1) ;

        return Class.forName (classname) ;
      }
      else
        {
          JOptionPane.showMessageDialog(null, "The database connection has been"
              + "closed unexpectedly.",
              "Database Connection Closed", JOptionPane.ERROR_MESSAGE);
        }
    }
    catch (Exception exception)
    {
      exception.printStackTrace () ;
    }
    return Object.class;
  }

}








public class EditableResultSet extends DBResultSet
{
  public EditableResultSet (String query)
  {
    super (query) ;
  }

  public boolean isCellEditable (int row, int col)
  {
    return true ;
  }

//think this method will just update the result set
  public void setValueAt(Object value, int row, int col)
  {
    String temp = "" ;
    try
    {
    int tempCol = col ;
    tempCol ++ ;
    if((tempCol == 4) || (tempCol == 5))
    {
      rs.updateString (tempCol, String.valueOf (value)) ;
    }
    else if (tempCol == 6)
    {
     
      //rs.updateDate(6,thiscal);
     
    }

      rs.updateRow(  );

    }
    catch (SQLException s)
    {
      s.printStackTrace();
    }
  }

}
0
CEHJCommented:
As what type is your date column stored in the RS?
0
CyartAuthor Commented:
java.sql.Date
0
CEHJCommented:
In setValueAt, i see no attempt to locate the row that's to be updated in the RS ...
0
CyartAuthor Commented:
I did not need to for the this part it knew the row already as confirmed by checking the db just can't make the java.sql.Date field editable.

if((tempCol == 4) || (tempCol == 5))
    {
      rs.updateString (tempCol, String.valueOf (value)) ;
     
    }
    else if (tempCol == 6)
0
CEHJCommented:
>>//rs.updateDate(6,thiscal);

What does 'thiscal' refer to?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CyartAuthor Commented:
Sorry forgot to close
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.