jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes JAVA Postgres insert Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JAVA Postgres insert Problem" Watch "JAVA Postgres insert Problem" New topic

JAVA Postgres insert Problem

Kamil Rak

Joined: Sep 11, 2012
Posts: 5
Hi there,

I am writing a database app in java and do hava a problem with inserting a value into the table.

So here it is: I have created the database in postgres and made a table named "klient"
There is a column named id_klienta which is an autoincremented primery key (there is also a sequence called idklienta_seq that is responsible for autoincrementation).

When I try to start the insert method I got the Exception:
missing from-clause for table "idklienta"

Here is the Java code:



Eclipse says there is a problem in the
pst.execute(); - KlientDB class.
If you could help me to fix that problem that would bu really great.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
What is "a problem" ? Surely Eclipse says more than that.
Kamil Rak

Joined: Sep 11, 2012
Posts: 5
I simpy forgot about it...
Here the console output:

org.postgresql.util.PSQLException: ERROR: missing from-clause for table "idklienta"
Pozycja: 121
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2101)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1834)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:379)
at bazaDanych.KlientDB.insert(KlientDB.java:153)
at bazaDanych.Testowa.main(Testowa.java:50)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32818

Welcome to CodeRanch! I added code tags to make the code easier to read.

I've never seen this syntax before in postgres:

Are you sure it is right? Do you have an example you got it from?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Kamil Rak

Joined: Sep 11, 2012
Posts: 5
You are right...
I tried different options and found out the right one. It should be nextval('idklienta_seq ') so the try block is:


Thanks for help!
I agree. Here's the link: http://aspose.com/file-tools
subject: JAVA Postgres insert Problem
jQuery in Action, 3rd edition