我正在尝试使用预准备语句将包含日期,时间和时区的字符串插入到我的数据库的时区字段的时间戳中.
问题是Timestamp.valueof函数没有考虑字符串包含的时区,因此它会导致错误.接受的格式是yyyy- [m] m- [d] d hh:mm:ss [.f ...],没有提到时区.
这是导致错误的确切代码:
pst.setTimestamp(2,Timestamp.valueOf("2012-08-24 14:00:00 +02:00"))
有什么方法可以克服它吗?提前致谢!
postgresql timestamp prepared-statement value-of timestamp-with-timezone
我想问一下如何创建一个圆圈radius=4km.我尝试了这个ST_Buffer功能,但它创建了一个更大的圆圈.(我通过将其多边形插入到新的kml文件中来查看创建的圆圈.)
这就是我想要的.
INSERT INTO camera(geom_circle) VALUES(geometry(ST_Buffer(georgaphy(ST_GeomFromText('POINT(21.304116745663165 38.68607570952619)')), 4000)))
Run Code Online (Sandbox Code Playgroud)
圆的中心是一个lon lat点,但我不知道它,SRID因为我从kml文件中导入了它.我是否需要SRID改变几何形状等?
我正在尝试执行以下查询
INSERT INTO hotspot(timestamp) VALUES
(timestamp with time zone '2012-10-25 14:00:00 +05:00' at time zone 'EET');
Run Code Online (Sandbox Code Playgroud)
我想将时间戳作为变量传递.
我的时间戳列是带时区的时间戳类型.
你知道如何做到这一点吗?
当我做...(Java,Postgresql)
String stm= "INSERT INTO hotspot(timestamp) VALUES(timestamp with time zone ? at time zone 'EET')";
pst = con.prepareStatement(stm);
pst.setString(1, "2012-08-24 14:00:00 +05:00");
pst.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
我在"$ 1"或附近收到语法错误
无论如何我能克服这个错误吗?先感谢您!!
更新:我尝试通过以下方式使用setTimestamp ...
Calendar c=Calendar.getInstance(TimeZone.getTimeZone("GMT+05:00"));
String stm= "INSERT INTO hotspot(timestamp) VALUES(?)";
pst = con.prepareStatement(stm);
pst.setTimestamp(1,Timestamp.valueOf("2012-01-05 14:00:00"), c );
pst.executeUpdate();
Run Code Online (Sandbox Code Playgroud)
我想数据库中的正确值应该是(关于我的本地时区是EET(+02))
2012-01-05 11:00:00 +02
但使用pgadmin我检查值,我得到
2012-01-05 14:00:00 +02
有什么建议?
postgresql syntax-error insert-update timestamp-with-timezone