【问题标题】:Insert jspinner time value to database将jspinner时间值插入数据库
【发布时间】:2017-02-08 19:10:25
【问题描述】:

我有两个 jspinner。一个包含 HH:mm 格式,另一个是简单的数字 (int) 微调器。

单击“保存”按钮时,我想更新包含 timeLimit(类型时间)和尝试(类型 int)列的数据库表。但我不知道如何将 jspinner 值保存到数据库中的时间类型。

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

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

我尝试了上面的代码,但最后一部分有一个错误,说 spinnerTime.getValue 是一个对象并且 setTime() 需要一个时间。我怎样才能转换和反对时间?还是有其他方法可以将具有时间值的 jspinner 插入到我的数据库中?任何帮助将不胜感激!

【问题讨论】:

  • 我想你不知道 Java 和 JavaScript 的区别

标签: java mysql netbeans time jspinner


【解决方案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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    相关资源
    最近更新 更多