【问题标题】:Insert in MySQL from JavaFX从 JavaFX 插入 MySQL
【发布时间】:2017-03-07 07:52:55
【问题描述】:

从 javafx 插入 mysql 问题,无论我做什么,我都会得到无效值。单击按钮时,我试图增加值。数据库中的第一个值是 Doc - 1,我希望下一个值是 Doc - 2 和 Doc - 3 的顺序。在查询中特别感谢任何帮助,因为一切正常。

@FXML
private void GenerateDocTag(ActionEvent event) throws SQLException {

    txtTag.setText( String.valueOf(doctorTag()));

}


private Integer doctorTag() throws SQLException {

    Connection connection = DBController.Connect();

    String query = "\n" +
            "select DocTag from doctors where substring('Doc - 1', -1);";
    resultSet = connection.createStatement().executeQuery(query);
    resultSet.first();
    int DOC_TAG = resultSet.getInt(1);
    return DOC_TAG + 1;
}

上面的错误是 getInt() - 'Doc - 1' 的无效值

【问题讨论】:

  • 先检查你的substring-valueSystem.out.println(resultSet.getString(1)),输出值是int类型吗?
  • 不要在 UI 线程内调用非 UI 代码,这会导致应用无响应和不良行为。

标签: java mysql javafx javafx-8


【解决方案1】:

假设你有下面的表结构:

value
------
Doc - 1
Doc - 2
Doc - 3

您需要将value 列的最大值和cast 获取到int,如果这是您的resultSet 所期望的,例如“

SELECT CAST(SUBSTRING(value, -1) AS UNSIGNED) AS VALUE 
FROM test1 ORDER BY value DESC LIMIT 1;

另一种方法是获取最大值 value 并在 Java 中执行 substring

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    • 2011-07-05
    • 2015-03-30
    • 2010-10-28
    相关资源
    最近更新 更多