2016-09-30 66 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