【问题标题】:storing the date in dbms将日期存储在 dbms 中
【发布时间】:2013-06-28 13:14:27
【问题描述】:

我在 html 输入字段中输入日期为date/month/year。假设用户输入的日期是 28/06/2013。我想将此日期存储在我的mysql dbms 中。

我该怎么做?我想存储日期以供以后检索。

【问题讨论】:

  • What have you tried 到目前为止?您能否发布一些您尝试过的代码,以便我们了解您希望如何完成此操作?

标签: java mysql sql date


【解决方案1】:

例如,如果日期是2008/4/5,那么我们可以使用以下代码对其进行格式化...

        String source="2008/4/5";              
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");                       
        java.sql.Date d= new java.sql.Date(format.parse(source).getTime());            

【讨论】:

    【解决方案2】:

    您不应直接在 SQL 中使用任何用户输入。相反,您应该进行参数化查询,并定义一个java.sql.Date 参数。然后,使用SimpleDateFormat Java 类将用户输入转换为 Date 对象,并用它填充参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 2021-09-14
      • 1970-01-01
      • 2018-07-29
      • 2012-03-18
      • 2019-12-16
      • 1970-01-01
      • 2016-08-07
      相关资源
      最近更新 更多