2016-09-30 165 views
0

我有两个jspinners。一个是HH:mm格式,另一个是简单数字(int)微调器。将jspinner时间值插入数据库

enter image description here

当SAVE按钮,点击我要更新包含的timeLimit(类型时间),并尝试(int类型)列的数据库表。但我不知道如何将jspinner值保存到我的数据库中的时间类型。

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

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

我试图上面的代码,但最后部分具有一个错误说spinnerTime.getValue是一个对象和时刻设定()需要的时间。我如何转换和反对时间?还是有其他的方式来插入一个带时间值的jspinner到我的数据库?任何帮助,将不胜感激!

+0

我觉得你不知道Java和JavaScript之间的区别 – R3tep

回答

1

这只是一个简单的被忽视的问题。我只是做了这个代码。

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(); 
+0

优雅!.......... – Viney