From: | Barry Lind <barry(at)xythos(dot)com> |
---|---|
To: | Tomisław Kityński <cromax(at)amiga(dot)pl> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: PreparedStatement and DB default values |
Date: | 2002-07-05 19:08:45 |
Message-ID: | 3D25EEBD.2090806@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
I doubt this is jdbc related. Can you turn on query tracing in the
server to see the exact SQL that the jdbc driver is sending to the
server and then run that same sql through psql?
thanks,
--Barry
Tomisław Kityński wrote:
>Hello,
>
>I have strange problem here. I have table declared as below:
>
> Table "users"
> Column | Type | Modifiers
>---------+-----------------------+------------------------------------------
>-------------
> id_user | integer | not null default
>nextval('"users_id_user_seq"'::text)
> first | character varying(24) | not null default '(imię)'
> last | character varying(32) | not null default '(nazwisko)'
> email | character varying(24) |
> vip | boolean | not null default 'f'
> ed | boolean | not null default 'f'
>Primary key: users_pkey
>Rules: on_delete_to_users,
> on_insert_to_users
>Triggers: RI_ConstraintTrigger_27009,
> RI_ConstraintTrigger_27011,
> RI_ConstraintTrigger_27019,
> RI_ConstraintTrigger_27021,
> RI_ConstraintTrigger_27028,
> RI_ConstraintTrigger_27030,
> RI_ConstraintTrigger_27063,
> RI_ConstraintTrigger_27065,
> RI_ConstraintTrigger_27086,
> RI_ConstraintTrigger_27088
>
>When I issue a statement from psql console like this:
>
>INSERT INTO users (first, last, email) VALUES ('Frst', 'Lst', 'em(at)il');
>
>(or AFAIR also from Statement by executeUpdate()), then id_user would be
>properly autogenerated. Unfortunately it does not work for
>PreparedStatement,
>thats what I get:
>
>INSERT INTO "users" ("first", "last", "email", "ed") VALUES (?, ?, ?, ?);
>java.sql.SQLException: ERROR: ExecAppend: Fail to add null value in not
>null attribute id_user
>
> at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:94)
> at org.postgresql.Connection.ExecSQL(Connection.java:398)
> at org.postgresql.jdbc2.Statement.execute(Statement.java:130)
> at org.postgresql.jdbc2.Statement.executeUpdate(Statement.java:73)
> at
>org.postgresql.jdbc2.PreparedStatement.executeUpdate(PreparedStatement.java:
>113)
>
>The first line is not the stack trace fragment, but update string construed
>by application, that is passed (the string) to the prepareStatement()
>method.
>
>Why it wants to add the null value to the column, which is not named in
>the statement and which have defined default value in database?
>
>I could use usual Statement, if there were no problems with escaping
>and/or quoting inserted/updated values. First--this is pain in a** to
>compose query and second, for different databases (I inted to write
>the code as far flexible and DB independent as I can) the escaping
>could be different (especially considering PSQL regexps). Is there
>any way to pass it by? Thank you for your help!
>
>
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Barry Lind | 2002-07-05 19:12:45 | Re: Retrieving binary data |
Previous Message | Barry Lind | 2002-07-05 17:18:29 | Re: [Fwd: [Fwd: Re: solved: fastpath error?]] |