0

I have two jspinners. the one contains an HH:mm format and the other one is a simple number(int) spinner.

enter image description here

when SAVE button clicked I want to update a database table that contains the timeLimit (type time) and attempts (type int) columns. But I dont know how to save a jspinner value to a time type in my database.

 String update = "Update qbank SET timeLimit = ? and attempts = ? where qbankID = ?";
            preparedStatement = connection.prepareStatement(update);

            preparedStatement.setTime(1, spinnerTime.getValue()); 

i tried the code above but the last part has an error saying spinnerTime.getValue is an object and setTime() requires a Time. How can I convert and object to time? or is there other way to insert a jspinner with time value to my database? any help would be appreciated!

R3tep
  • 12,512
  • 10
  • 48
  • 75
Kent Abrio
  • 445
  • 2
  • 9
  • 27

1 Answers1

1

It was just a simple overlooked problem. I just did this code.

 Time time; int attempt;
            time = (Time) spinnerTime.getValue();
            attempt = Integer.parseInt(spinnerAttempt.getValue().toString());

        String update = "Update qbank SET timeLimit = ? and attempts = ? where qbankID = ?";
        preparedStatement = connection.prepareStatement(update);

        preparedStatement.setTime(1, time);
        preparedStatement.setInt(2, attempt);
        preparedStatement.setInt(3, qbankID);
        preparedStatement.executeUpdate();
Kent Abrio
  • 445
  • 2
  • 9
  • 27