I am trying to execute the following query
INSERT INTO hotspot(timestamp) VALUES (timestamp with time zone '2012-10-25 14:00:00 +05:00' at time zone 'EET');
and I want to pass the timestamp as a variable.
My timestamp column is a timestamp type with a time zone.
Do you know how to do this?
When I do ... (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();
I get a syntax error at or around $ 1 "
Is there any way to overcome this error? Thanks in advance!
Update: I tried using setTimestamp as follows ...
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();
I believe that the correct value in the DB should be (relative to the fact that my local time zone is EET (+02))
2012-01-05 11:00:00 +02
but using pgadmin i check the value and i get
2012-01-05 14:00:00 +02
Any suggestions?
source share