小编Pet*_*ter的帖子

如何使用 JDBC 将日期时间添加到我的 SQL 数据库中

目前,我正在尝试从 JavaFX GUI 将我的日期时间添加到 SQL 中,但我不断收到数字格式异常错误。日期时间格式是yyyy-MM-dd HH:mm:ss,但我也可以像 12:30 等那样添加。

private void doAdd() {
    //Input from the user in GUI format
    int EntryID = Integer.valueOf(tfEntryID.getText());
    String PersonName = tfPersonName.getText();
    int CheckInTime = Integer.parseInt(tfCheckInTime.getText());
    String CheckTime = String.valueOf(CheckInTime);
    Date date = new Date(CheckInTime);
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
    String currentDateTime = format.format(date);
    String insertSql = String.format("INSERT INTO entry_records(
        EntryID, PersonName, CheckTime) VALUES ('%s', '%s', %s)",
        EntryID , PersonName ,currentDateTime );
    int rowsAdded = DBUtil.execSQL(insertSql);
    if (rowsAdded == 1) …
Run Code Online (Sandbox Code Playgroud)

java datetime jdbc

1
推荐指数
1
解决办法
47
查看次数

标签 统计

datetime ×1

java ×1

jdbc ×1