Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 拆下';T';从日期时间转换为sql日期_Java_Postgresql_Datetime - Fatal编程技术网

Java 拆下';T';从日期时间转换为sql日期

Java 拆下';T';从日期时间转换为sql日期,java,postgresql,datetime,Java,Postgresql,Datetime,我将json字段设置为 {"dateTime" : "2018-06-02T15:49:23"} 现在我需要在postgres存储过程中使用这个字段作为输入参数。在SP中,输入字段类型为timestamp,因为我需要在sql timestamp中转换此dateTime,中间不带“T”(仅2018-06-02 15:49:23)。 非常感谢您对如何在Java中实现它的任何建议。您可以选择它: t=# select ('{"dateTime" : "2018-06-02T15:49:23"}'::

我将json字段设置为

{"dateTime" : "2018-06-02T15:49:23"}
现在我需要在postgres存储过程中使用这个字段作为输入参数。在SP中,输入字段类型为timestamp,因为我需要在sql timestamp中转换此dateTime,中间不带“T”(仅2018-06-02 15:49:23)。
非常感谢您对如何在Java中实现它的任何建议。

您可以选择它:

t=# select ('{"dateTime" : "2018-06-02T15:49:23"}'::json->>'dateTime')::timestamp;
      timestamp
---------------------
 2018-06-02 15:49:23
(1 row)

我建议您在Java中将字符串解析为
LocalDateTime
,而不仅仅是删除
T
。one arg
LocalDateTime.parse
方法执行以下操作:

    LocalDateTime dateTime = LocalDateTime.parse("2018-06-02T15:49:23");
然后,您可以将
LocalDateTime
传递给存储过程,它需要一个时间戳

    CallableStatement cs = yourConnection.prepareCall("{call your_stored_procedure(?)}");
    cs.setObject(1, dateTime);

在过去,我们会在这里使用
java.sql.Timestamp
。那门课已经过时很久了。对于Java 8和JDBC 4.2或更高版本,我们更喜欢使用
LocalDateTime
Instant
select(“{”dateTime:“2018-06-02T15:49:23”}”:json->“dateTime”)::timestamp
-您可以选择它,无需在Java中解析,而只需删除
T
我建议您在Java中将字符串解析为
LocalDateTime
(一个参数
LocalDateTime.parse
方法就是这样做的),并将
LocalDateTime
传递给您的存储过程。@Ole yes。!LocalDateTime在这里为我工作。使用Joda时间?
    CallableStatement cs = yourConnection.prepareCall("{call your_stored_procedure(?)}");
    cs.setObject(1, dateTime);