pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lucas Sanabio <lsanabio@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Inserting the wrong date
Date: Wed, 25 Jan 2006 15:45:59 -0300
Message-ID: <91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com> (raw)

Hi everyone! I'm having an problem when I try to insert data into a
timestamp field, let me try to explain what is going in on.

I developed my application at my local machine and at this machine
everything is working as it should, but when I deployed the application into
the production server, every time I save an timestamp it saves it one hour
before. The method that is inserting the data is pasted below:

############################
public int inserir(CompromissoVO vo, Connection conn) throws Exception {
        PreparedStatement stp = null;

        int chave = 0;

        final String sql = "INSERT INTO "
                + ESQUEMA
                + ".compromisso (com_id, com_criacao, com_data, "
                + "com_titulo, com_confidencial, tco_id, com_agendamento,
aud_id, "
                + "via_id, soe_id)"
                + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        try {

            chave = ConnectionManager.getSequence("comp_seq");
            int i = 1;

            stp = conn.prepareStatement(sql);

            stp.setInt(i++, chave);
            Date agora = new Date();
            stp.setTimestamp(i++, new Timestamp(agora.getTime()));

            SimpleDateFormat sd = new SimpleDateFormat("dd/MM/yyyy
HH:mm:ss");
            log.debug("Inserir - Data compromisso: " + sd.format(vo.getData
()));
            stp.setTimestamp(i++, new Timestamp(vo.getData().getTime()));
            stp.setString(i++, vo.getTitulo());
            stp.setString(i++, vo.getConfidencial());
            stp.setInt(i++, vo.getTipo().getCodigo());
            stp.setString(i++, vo.getTipoAgendamento());
            if (vo.getAudiencia() > 0){
                stp.setInt(i++, vo.getAudiencia());
            } else {
                stp.setNull(i++, Types.INTEGER);
            }
            if (vo.getViagem() > 0){
                stp.setInt(i++, vo.getViagem());
            } else {
                stp.setNull(i++, Types.INTEGER);
            }
            if (vo.getSolenidade() > 0){
                stp.setInt(i++, vo.getSolenidade());
            } else {
                stp.setNull(i++, Types.INTEGER);
            }

            stp.execute();

        } catch (NegocioException ne) {
            throw ne;
        } catch (Exception e) {
            log.debug("sql: " + sql);
            throw new NegocioException("error.inserir.compromisso", e);
        }

        return chave;
    }
############################

The vo.getData() return the date which was typed by the user, I logged the
date to see if it was right and I got it was, but when I look at the
database the date is one hour before.

Log: 2006-01-25 16:05:08,877 -> DEBUG (CompromissoDAO.java:140) - Alterar -
Data compromisso: 12/01/2006 12:00:00
The data which was saved at the database: 2006-01-12 11:00:00

My table script is:

CREATE TABLE compromisso
(
  com_id numeric(6) NOT NULL,
  com_criacao timestamp NOT NULL,
  com_data timestamp NOT NULL,
  com_titulo varchar(200) NOT NULL,
  com_confidencial varchar(400),
  com_agendamento char(1),
  tco_id numeric(6) NOT NULL,
  aud_id numeric(6),
  via_id numeric(6),
  soe_id numeric(6),
  CONSTRAINT compromisso_pk PRIMARY KEY (com_id),
  CONSTRAINT com_tipocompromisso_fk FOREIGN KEY (tco_id) REFERENCES
compromisso_tipo (tco_id) ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT compromisso_audiencia_fk FOREIGN KEY (aud_id) REFERENCES
registro_audiencia (aud_id) ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT compromisso_solenidade_fk FOREIGN KEY (soe_id) REFERENCES
registro_solenidade (soe_id) ON UPDATE RESTRICT ON DELETE RESTRICT,
  CONSTRAINT compromisso_viagem_fk FOREIGN KEY (via_id) REFERENCES
registro_viagem (via_id) ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITHOUT OIDS;
ALTER TABLE compromisso OWNER TO uzzi;
GRANT ALL ON TABLE compromisso TO uzzi;


Does any one have an idea what is going in on?

Thanks,

--
Lucas Sanabio
-----------------------------------------------------------------------------
Sun Certified Programmer for the Java 2 Platform
Consultor Java - Marx Tecnologia
Email: lucas@marx.com.br
Cel: (61) 8402-8876

view thread (2+ messages)  latest in thread

Message-ID: <91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com>
Permalink:  ../91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com/
Also on:    postgresql.org/message-id/91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: lsanabio@gmail.com
  Subject: Re: Inserting the wrong date
  In-Reply-To: <91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com>
  References: <91d5bf2c0601251045p5f5d5b6fp405c30b513cbdc6a@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox