gpt4 book ai didi

java - 将 dd/mm/yyyy 日期格式插入数据库表

转载 作者:行者123 更新时间:2023-11-30 01:33:31 24 4
gpt4 key购买 nike

我正在尝试将 dd/mm/yyyy 日期格式插入到我的数据库表中。数据库中日期列的数据类型是日期,我的SQL插入语句是:

INSERT INTO sm_product(productName, productDescription, productPrice, productQuantity, productStatus)
VALUES ('" + name + "', '" + desc + "', " + price + ", " + quantity + ", 'Available', '" + date + "'";

但是,当我将日期变量添加到 SQL 语句中时,netbeans 显示错误。

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

它将日期存储为:

Wed Jun 19 17:42:26 SGT 2013

我在用户界面中得到了 dd/mm/yyyy 日期格式:

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
dateFormat.format(date);

这种格式不是我想要的。所以我想知道我应该如何修改我的SQL语句来解决这个问题。

提前致谢。

最佳答案

如果您使用的是 SQL Server,则可以使用

REPLACE(CONVERT(VARCHAR(11),date,105),'-','/')

关于java - 将 dd/mm/yyyy 日期格式插入数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17188155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com