从JavaFX插入MySQL

时间:2017-03-07 07:52:56

标签: java mysql javafx javafx-8

从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'

1 个答案:

答案 0 :(得分:0)

假设您有以下表结构:

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并执行import datetime import logging logging.basicConfig(filename='loghistory.log', filemode='w', level=logging.DEBUG) logger = logging.getLogger('loghistory.log') ch = logging.FileHandler('loghistory.log',mode='w') # to empty exisiting file: logging.FileHandler('loghistory.log', mode ='w') formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s',datefmt='%m/%d/%Y %I:%M:%S %p') ch.setFormatter(formatter) logger.addHandler(ch) logger.setLevel(logging.DEBUG) if q2==0 and q1==0: logger.debug('No airplanes within 5 km') else: if q2 ==0 and q1>0: logger.debug('At least 1 airplane within 5 km') else: if q2>0: logger.debug('At least 1 airplane within 2 km')